PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.2.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.2.1
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / cache / class-lp-cache.php

class-lp-cache.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.2.1, at inc/cache/class-lp-cache.php

93 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LP_Cache
5 *
6 * @author tungnx
7 * @since 4.0.8
8 * @version 1.0.2
9 */
10 defined( 'ABSPATH' ) || exit();
11
12 class LP_Cache {
13 /**
14 * @var string Key group parent
15 */
16 protected $key_group_parent = 'learn_press/';
17 /**
18 * @var string Key group child(external)
19 */
20 protected $key_group_child = '';
21 /**
22 * @var string Add key group parent with key group child
23 */
24 protected $key_group = '';
25
26 protected function __construct() {
27 $this->key_group = $this->key_group_parent . $this->key_group_child;
28 }
29
30 /**
31 * Set cache
32 *
33 * @param string $key
34 * @param mixed $data
35 * @param int $expire
36 */
37 public function set_cache( string $key, $data, int $expire = 0 ) {
38 wp_cache_set( $key, $data, $this->key_group, $expire );
39 }
40
41 /**
42 * Get cache
43 *
44 * @param string $key
45 * @return false|mixed
46 */
47 public function get_cache( string $key ) {
48 return wp_cache_get( $key, $this->key_group );
49 }
50
51 /**
52 * Set value for first load page on one process
53 * Apply for query call same
54 *
55 * @param string $type
56 * @param string $key
57 * @param $val mixed
58 *
59 * @author tungnx
60 * @version 1.0.0
61 * @sicne 4.1.4.1
62 * @return false|mixed|string
63 */
64 public static function cache_load_first( string $type = 'get', string $key = '', $val = '' ) {
65 static $first_set_value = array();
66
67 if ( 'get' === $type ) {
68 if ( ! array_key_exists( $key, $first_set_value ) ) {
69 return false;
70 } else {
71 return $first_set_value[ $key ];
72 }
73 } elseif ( 'set' === $type ) {
74 $first_set_value[ $key ] = $val;
75
76 return $first_set_value[ $key ];
77 }
78 }
79
80 /**
81 * Clear cache by key
82 *
83 * @param $key
84 */
85 public function clear( $key ) {
86 wp_cache_delete( $key, $this->key_group );
87 }
88
89 public function clear_all() {
90 wp_cache_flush();
91 }
92 }
93