Skip to content

Commit

Permalink
= 4.2.5.4 =
Browse files Browse the repository at this point in the history
~ Remove cache on get_courses method, handle another place.
  • Loading branch information
tungnxt89 committed Nov 2, 2023
1 parent 3933c38 commit 9a852fc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
13 changes: 13 additions & 0 deletions inc/cache/class-lp-courses-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class LP_Courses_Cache extends LP_Cache {
* @var string Save list keys cached to clear
*/
public static $keys = 'keys';
const KEYS_QUERY_COURSES = 'keys/query_courses';
const KEYS_QUERY_TOTAL_COURSES = 'keys/query_courses/total';
const KEYS_COUNT_COURSES_FREE = 'keys/count_courses_free';
const KEYS_COUNT_STUDENT_COURSES = 'keys/count_student_courses';

Expand Down Expand Up @@ -63,4 +65,15 @@ public function save_cache_keys_count_courses_free( string $key_cache ) {
public function save_cache_keys_count_student_courses( string $key_cache ) {
$this->save_cache_keys( self::KEYS_COUNT_STUDENT_COURSES, $key_cache );
}

/**
* Store list keys cache query courses
*
* @param string $key_cache
* @since 4.2.5.4
* @version 1.0.0
*/
public function save_cache_keys_query_courses( string $key_cache ) {
$this->save_cache_keys( self::KEYS_QUERY_COURSES, $key_cache );
}
}
31 changes: 16 additions & 15 deletions inc/course/class-lp-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,15 @@ public static function get_courses( LP_Course_Filter $filter, int &$total_rows =
$lp_course_db = LP_Course_DB::getInstance();

try {
$key_cache = md5( json_encode( $filter ) );
$key_cache_total_rows = md5( json_encode( $filter ) . 'total_rows' );
$courses_cache = LP_Courses_Cache::instance()->get_cache( $key_cache );
/*$lp_courses_cache = new LP_Courses_Cache( true );
$key_cache = 'query-courses-' . md5( json_encode( $filter ) );
$key_cache_total_rows = 'query-courses-total-' . md5( json_encode( $filter ) );
$courses_cache = $lp_courses_cache->get_cache( $key_cache );
if ( false !== $courses_cache ) {
$total_rows = LP_Courses_Cache::instance()->get_cache( $key_cache_total_rows );
return $courses_cache;
}
$total_rows = $lp_courses_cache->get_cache( $key_cache_total_rows );
return LP_Helper::json_decode( $courses_cache );
}*/

// Sort by
$filter->sort_by = (array) $filter->sort_by;
Expand Down Expand Up @@ -656,15 +657,15 @@ public static function get_courses( LP_Course_Filter $filter, int &$total_rows =
$filter = apply_filters( 'lp/courses/filter', $filter );
$courses = LP_Course_DB::getInstance()->get_courses( $filter, $total_rows );

LP_Courses_Cache::instance()->set_cache( $key_cache, $courses );
LP_Courses_Cache::instance()->set_cache( $key_cache_total_rows, $total_rows );

/**
* Save key cache to array to clear
* @see LP_Background_Single_Course::save_post() - clear cache when save post
*/
//LP_Courses_Cache::instance()->save_cache_keys( $key_cache );
//LP_Courses_Cache::instance()->save_cache_keys( $key_cache_total_rows );
// $lp_courses_cache->set_cache( $key_cache, json_encode( $courses ) );
// $lp_courses_cache->set_cache( $key_cache_total_rows, $total_rows );
//
// /**
// * Save key cache to array to clear
// * @see LP_Background_Single_Course::save_post() - clear cache when save post
// */
// $lp_courses_cache->save_cache_keys_query_courses( $key_cache );
// $lp_courses_cache->save_cache_keys( LP_Courses_Cache::KEYS_QUERY_TOTAL_COURSES, $key_cache_total_rows );
} catch ( Throwable $e ) {
$courses = [];
error_log( __FUNCTION__ . ': ' . $e->getMessage() );
Expand Down

0 comments on commit 9a852fc

Please sign in to comment.