1 | <?php |
||
13 | class Cache { |
||
14 | use Module, Events; |
||
15 | |||
16 | protected static $driver = null, |
||
17 | $enabled = true; |
||
18 | |||
19 | public static function get($key, $default='', $expire=0){ |
||
34 | |||
35 | /** |
||
36 | * Load cache drivers with a FCFS strategy |
||
37 | * |
||
38 | * @method using |
||
39 | * @param mixed $driver can be a single driver name string, an array of driver names or a map [ driver_name => driver_options array ] |
||
40 | * @return bool true if a driver was loaded |
||
41 | * @example |
||
42 | * |
||
43 | * Cache::using('redis'); |
||
44 | * Cache::using(['redis','files','memory']); // Prefer "redis" over "files" over "memory" caching |
||
45 | * Cache::using([ |
||
46 | * 'redis' => [ |
||
47 | * 'host' => '127.0.0.1', |
||
48 | * 'prefix' => 'mycache', |
||
49 | * ], |
||
50 | * 'files' => [ |
||
51 | * 'cache_dir' => '/tmp', |
||
52 | * ], |
||
53 | * 'memory' |
||
54 | * ]); |
||
55 | * |
||
56 | */ |
||
57 | public static function using($driver){ |
||
74 | |||
75 | /** |
||
76 | * Returns/Set master switch on cache. |
||
77 | * |
||
78 | * @method enabled |
||
79 | * |
||
80 | * @param boolean $enabled Enable/Disable the cache status. |
||
81 | * |
||
82 | * @return boolean Cache on/off status |
||
83 | */ |
||
84 | public static function enabled($enabled=null){ |
||
87 | |||
88 | public static function set($key, $value, $expire=0){ |
||
91 | |||
92 | public static function delete($key){ |
||
95 | |||
96 | public static function exists($key){ |
||
97 | return static::$enabled && static::$driver->exists(static::hash($key)); |
||
98 | } |
||
99 | |||
100 | public static function flush(){ |
||
103 | |||
104 | public static function inc($key, $value=1){ |
||
107 | |||
108 | public static function dec($key, $value=1){ |
||
111 | |||
112 | public static function hash($key, $group=null){ |
||
121 | } |
||
122 | |||
125 |