diff --git a/inc/cache/class-lp-courses-cache.php b/inc/cache/class-lp-courses-cache.php index 1e1762b0b..818e966df 100644 --- a/inc/cache/class-lp-courses-cache.php +++ b/inc/cache/class-lp-courses-cache.php @@ -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'; @@ -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 ); + } } diff --git a/inc/course/class-lp-course.php b/inc/course/class-lp-course.php index 8522f84a5..b4ca9ed88 100644 --- a/inc/course/class-lp-course.php +++ b/inc/course/class-lp-course.php @@ -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; @@ -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() );