| @@ -1,69 +1,69 @@ | ||
| 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_User_Items_Cache extends LP_Cache { | |
| 13 | - protected $key_group_child = 'user-items'; | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * @param $has_thim_cache bool | |
| 17 | - */ | |
| 18 | - public function __construct( $has_thim_cache = false ) { | |
| 19 | - parent::__construct( $has_thim_cache ); | |
| 20 | - } | |
| 21 | - | |
| 22 | - public function set_user_item( $keys = [], string $value = '' ) { | |
| 23 | - $key = implode( '/', $keys ); | |
| 24 | - $this->set_cache( $key, $value ); | |
| 25 | - } | |
| 26 | - | |
| 27 | - public function get_user_item( $keys = [] ) { | |
| 28 | - $key = implode( '/', $keys ); | |
| 29 | - $rs = LP_Cache::cache_load_first( 'get', $key ); | |
| 30 | - if ( false !== $rs ) { | |
| 31 | - return $rs; | |
| 32 | - } | |
| 33 | - | |
| 34 | - $rs = $this->get_cache( $key ); | |
| 35 | - LP_Cache::cache_load_first( 'set', $key, $rs ); | |
| 36 | - | |
| 37 | - return $rs; | |
| 38 | - } | |
| 39 | - | |
| 40 | - public function clean_user_item( $keys = [] ) { | |
| 41 | - $key = implode( '/', $keys ); | |
| 42 | - $this->clear( $key ); | |
| 43 | - } | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * For cache clear all user items has course_id | |
| 47 | - * | |
| 48 | - * @param $course_id int | |
| 49 | - * | |
| 50 | - * @return bool|int|mysqli_result|resource|null | |
| 51 | - * @throws Exception | |
| 52 | - */ | |
| 53 | - public function clean_user_items_by_course( int $course_id = 0 ) { | |
| 54 | - $thim_cache_db = Thim_Cache_DB::instance(); | |
| 55 | - $query = $thim_cache_db->wpdb->prepare( | |
| 56 | - "DELETE FROM {$thim_cache_db->table_name} | |
| 57 | - WHERE key_cache REGEXP %s", | |
| 58 | - "learn_press/user-items/[0-9]*/{$course_id}/" . LP_COURSE_CPT | |
| 59 | - ); | |
| 60 | - | |
| 61 | - $rs = $thim_cache_db->wpdb->query( $query ); | |
| 62 | - | |
| 63 | - if ( $thim_cache_db->wpdb->last_error ) { | |
| 64 | - throw new Exception( $thim_cache_db->wpdb->last_error ); | |
| 65 | - } | |
| 66 | - | |
| 67 | - return $rs; | |
| 68 | - } | |
| 69 | -} | |
| 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_User_Items_Cache extends LP_Cache { | |
| 13 | + protected $key_group_child = 'user-items'; | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * @param $has_thim_cache bool | |
| 17 | + */ | |
| 18 | + public function __construct( $has_thim_cache = false ) { | |
| 19 | + parent::__construct( $has_thim_cache ); | |
| 20 | + } | |
| 21 | + | |
| 22 | + public function set_user_item( $keys = [], string $value = '' ) { | |
| 23 | + $key = implode( '/', $keys ); | |
| 24 | + $this->set_cache( $key, $value ); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public function get_user_item( $keys = [] ) { | |
| 28 | + $key = implode( '/', $keys ); | |
| 29 | + $rs = LP_Cache::cache_load_first( 'get', $key ); | |
| 30 | + if ( false !== $rs ) { | |
| 31 | + return $rs; | |
| 32 | + } | |
| 33 | + | |
| 34 | + $rs = $this->get_cache( $key ); | |
| 35 | + LP_Cache::cache_load_first( 'set', $key, $rs ); | |
| 36 | + | |
| 37 | + return $rs; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public function clean_user_item( $keys = [] ) { | |
| 41 | + $key = implode( '/', $keys ); | |
| 42 | + $this->clear( $key ); | |
| 43 | + } | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * For cache clear all user items has course_id | |
| 47 | + * | |
| 48 | + * @param $course_id int | |
| 49 | + * | |
| 50 | + * @return bool|int|mysqli_result|resource|null | |
| 51 | + * @throws Exception | |
| 52 | + */ | |
| 53 | + public function clean_user_items_by_course( int $course_id = 0 ) { | |
| 54 | + $thim_cache_db = Thim_Cache_DB::instance(); | |
| 55 | + $query = $thim_cache_db->wpdb->prepare( | |
| 56 | + "DELETE FROM {$thim_cache_db->table_name} | |
| 57 | + WHERE key_cache REGEXP %s", | |
| 58 | + "learn_press/user-items/[0-9]*/{$course_id}/" . LP_COURSE_CPT | |
| 59 | + ); | |
| 60 | + | |
| 61 | + $rs = $thim_cache_db->wpdb->query( $query ); | |
| 62 | + | |
| 63 | + if ( $thim_cache_db->wpdb->last_error ) { | |
| 64 | + throw new Exception( $thim_cache_db->wpdb->last_error ); | |
| 65 | + } | |
| 66 | + | |
| 67 | + return $rs; | |
| 68 | + } | |
| 69 | +} | |