1 | <?php |
||
15 | class Cache { |
||
16 | use Singleton; |
||
17 | /** |
||
18 | * Cache state |
||
19 | * |
||
20 | * @var bool |
||
21 | */ |
||
22 | protected $state = true; |
||
23 | /** |
||
24 | * Initialization state |
||
25 | * @var bool |
||
26 | */ |
||
27 | protected $init = false; |
||
28 | /** |
||
29 | * Name of cache engine |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $engine; |
||
33 | /** |
||
34 | * Instance of cache engine object |
||
35 | * |
||
36 | * @var Cache\_Abstract |
||
37 | */ |
||
38 | protected $engine_instance; |
||
39 | /** |
||
40 | * Initialization, creating cache engine instance |
||
41 | */ |
||
42 | 60 | protected function construct () { |
|
49 | /** |
||
50 | * Returns instance for simplified work with cache, when using common prefix |
||
51 | * |
||
52 | * @param string $prefix |
||
53 | * |
||
54 | * @return Prefix |
||
55 | */ |
||
56 | 40 | static function prefix ($prefix) { |
|
57 | 40 | return new Prefix($prefix); |
|
58 | } |
||
59 | /** |
||
60 | * Get item from cache |
||
61 | * |
||
62 | * If item not found and $callback parameter specified - closure must return value for item. This value will be set for current item, and returned. |
||
63 | * |
||
64 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
65 | * @param callable|null $callback |
||
66 | * |
||
67 | * @return false|mixed Returns item on success of <b>false</b> on failure |
||
68 | */ |
||
69 | 60 | function get ($item, $callback = null) { |
|
83 | /** |
||
84 | * Put or change data of cache item |
||
85 | * |
||
86 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
87 | * @param mixed $data |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | 40 | function set ($item, $data) { |
|
99 | /** |
||
100 | * Delete item from cache |
||
101 | * |
||
102 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
103 | * |
||
104 | * @return bool |
||
105 | */ |
||
106 | 34 | function del ($item) { |
|
119 | /** |
||
120 | * Clean cache by deleting all items |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | 10 | function clean () { |
|
127 | /** |
||
128 | * Cache state enabled/disabled |
||
129 | * |
||
130 | * @return bool |
||
131 | */ |
||
132 | 10 | function cache_state () { |
|
135 | /** |
||
136 | * Disable cache |
||
137 | */ |
||
138 | 10 | function disable () { |
|
141 | /** |
||
142 | * Get item from cache |
||
143 | * |
||
144 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
145 | * |
||
146 | * @return false|mixed Returns item on success of <b>false</b> on failure |
||
147 | */ |
||
148 | 56 | function __get ($item) { |
|
151 | /** |
||
152 | * Put or change data of cache item |
||
153 | * |
||
154 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
155 | * @param mixed $data |
||
156 | */ |
||
157 | 18 | function __set ($item, $data) { |
|
160 | /** |
||
161 | * Delete item from cache |
||
162 | * |
||
163 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
164 | */ |
||
165 | 14 | function __unset ($item) { |
|
168 | } |
||
169 |