| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class LP_Course_Cache |
| 5 |
* |
| 6 |
* @author tungnx |
| 7 |
* @since 4.0.9 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
defined( 'ABSPATH' ) || exit(); |
| 11 |
|
| 12 |
class LP_Course_Cache extends LP_Cache { |
| 13 |
protected static $instance; |
| 14 |
protected $key_group_child = 'course'; |
| 15 |
protected $key_total_students_enrolled = 'total-students-enrolled'; |
| 16 |
protected $key_total_students_enrolled_or_purchased = 'total-students-enrolled-or-purchased'; |
| 17 |
|
| 18 |
/** |
| 19 |
* Get instance |
| 20 |
* |
| 21 |
* @return self |
| 22 |
*/ |
| 23 |
public static function instance(): self { |
| 24 |
if ( is_null( self::$instance ) ) { |
| 25 |
self::$instance = new self(); |
| 26 |
} |
| 27 |
|
| 28 |
return self::$instance; |
| 29 |
} |
| 30 |
|
| 31 |
public function __construct( $has_thim_cache = false ) { |
| 32 |
parent::__construct( $has_thim_cache ); |
| 33 |
} |
| 34 |
|
| 35 |
public function set_total_students_enrolled( $course_id, $total ) { |
| 36 |
$key = "{$course_id}/{$this->key_total_students_enrolled}"; |
| 37 |
$this->set_cache( $key, $total ); |
| 38 |
} |
| 39 |
|
| 40 |
public function get_total_students_enrolled( $course_id ) { |
| 41 |
$key = "{$course_id}/{$this->key_total_students_enrolled}"; |
| 42 |
return $this->get_cache( $key ); |
| 43 |
} |
| 44 |
|
| 45 |
public function clean_total_students_enrolled( $course_id ) { |
| 46 |
$key = "{$course_id}/{$this->key_total_students_enrolled}"; |
| 47 |
$this->clear( $key ); |
| 48 |
} |
| 49 |
|
| 50 |
public function set_total_students_enrolled_or_purchased( $course_id, $total ) { |
| 51 |
$key = "{$course_id}/{$this->key_total_students_enrolled_or_purchased}"; |
| 52 |
$this->set_cache( $key, $total ); |
| 53 |
LP_Cache::cache_load_first( 'set', $key, $total ); |
| 54 |
} |
| 55 |
|
| 56 |
public function get_total_students_enrolled_or_purchased( $course_id ) { |
| 57 |
$key = "{$course_id}/{$this->key_total_students_enrolled_or_purchased}"; |
| 58 |
$total = LP_Cache::cache_load_first( 'get', $key ); |
| 59 |
if ( false !== $total ) { |
| 60 |
return $total; |
| 61 |
} |
| 62 |
|
| 63 |
$total = $this->get_cache( $key ); |
| 64 |
LP_Cache::cache_load_first( 'set', $key, $total ); |
| 65 |
|
| 66 |
return $total; |
| 67 |
} |
| 68 |
|
| 69 |
public function clean_total_students_enrolled_or_purchased( $course_id ) { |
| 70 |
$key = "{$course_id}/{$this->key_total_students_enrolled_or_purchased}"; |
| 71 |
$this->clear( $key ); |
| 72 |
} |
| 73 |
} |
| 74 |
|