1 | <?php |
||
15 | class Prefix { |
||
16 | protected $prefix; |
||
17 | /** |
||
18 | * Initialization with some prefix |
||
19 | * |
||
20 | * @param string $prefix |
||
21 | */ |
||
22 | 16 | function __construct ($prefix) { |
|
25 | /** |
||
26 | * Get item from cache |
||
27 | * |
||
28 | * If item not found and $callback parameter specified - closure must return value for item. This value will be set for current item, and returned. |
||
29 | * |
||
30 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
31 | * @param callable|null $callback |
||
32 | * |
||
33 | * @return false|mixed Returns item on success of <b>false</b> on failure |
||
34 | */ |
||
35 | 16 | function get ($item, $callback = null) { |
|
38 | /** |
||
39 | * Put or change data of cache item |
||
40 | * |
||
41 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
42 | * @param mixed $data |
||
43 | * |
||
44 | * @return bool |
||
45 | */ |
||
46 | 2 | function set ($item, $data) { |
|
47 | 2 | return Cache::instance()->set("$this->prefix/$item", $data); |
|
48 | } |
||
49 | /** |
||
50 | * Delete item from cache |
||
51 | * |
||
52 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | 10 | function del ($item) { |
|
59 | /** |
||
60 | * Get item from cache |
||
61 | * |
||
62 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
63 | * |
||
64 | * @return false|mixed Returns item on success of <b>false</b> on failure |
||
65 | */ |
||
66 | 2 | function __get ($item) { |
|
67 | 2 | return $this->get($item); |
|
68 | } |
||
69 | /** |
||
70 | * Put or change data of cache item |
||
71 | * |
||
72 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
73 | * @param mixed $data |
||
74 | */ |
||
75 | 2 | function __set ($item, $data) { |
|
76 | 2 | $this->set($item, $data); |
|
77 | 2 | } |
|
78 | /** |
||
79 | * Delete item from cache |
||
80 | * |
||
81 | * @param string $item May contain "/" symbols for cache structure, for example users/<i>user_id</i> |
||
82 | */ |
||
83 | 10 | function __unset ($item) { |
|
86 | } |
||
87 |