Skip to content

Commit

Permalink
= 4.2.7.4 =
Browse files Browse the repository at this point in the history
~ Handle cache for "find" method on UserCourseModel class
  • Loading branch information
tungnxt89 committed Nov 21, 2024
1 parent 9d1a953 commit 1c02a97
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion inc/Models/UserItems/UserCourseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,33 @@ public function get_course_model() {
* @param bool $check_cache
*
* @return false|UserItemModel|static
* @since 4.2.7
* @version 1.0.1
*/
public static function find( int $user_id, int $course_id, bool $check_cache = false ) {
$filter = new LP_User_Items_Filter();
$filter->user_id = $user_id;
$filter->item_id = $course_id;
$filter->item_type = LP_COURSE_CPT;
$key_cache = "userCourseModel/find/{$user_id}/{$course_id}/{$filter->item_type}";
$lpUserCourseCache = new LP_Cache();

// Check cache
if ( $check_cache ) {
$userCourseModel = $lpUserCourseCache->get_cache( $key_cache );
if ( $userCourseModel instanceof UserCourseModel ) {
return $userCourseModel;
}
}

$userCourseModel = static::get_user_item_model_from_db( $filter );

// Set cache
if ( $userCourseModel instanceof UserCourseModel ) {
$lpUserCourseCache->set_cache( $key_cache, $userCourseModel );
}

return static::get_user_item_model_from_db( $filter );
return $userCourseModel;
}

/**
Expand Down

0 comments on commit 1c02a97

Please sign in to comment.