1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php namespace System;
- class Cache {
-
- private static $drivers = array();
-
- public static function driver($driver = null)
- {
- if (is_null($driver))
- {
- $driver = Config::get('cache.driver');
- }
- return (array_key_exists($driver, static::$drivers))
- ? static::$drivers[$driver]
- : static::$drivers[$driver] = Cache\Factory::make($driver);
- }
-
-
- public static function get($key, $default = null, $driver = null)
- {
- if (array_key_exists($key, static::driver($driver)->items))
- {
- return static::driver($driver)->items[$key];
- }
- if (is_null($item = static::driver($driver)->get($key)))
- {
- return is_callable($default) ? call_user_func($default) : $default;
- }
- return $item;
- }
-
- public static function remember($key, $default, $minutes, $driver = null)
- {
- if ( ! is_null($item = static::get($key)))
- {
- return $item;
- }
- $default = is_callable($default) ? call_user_func($default) : $default;
- static::driver($driver)->put($key, $default, $minutes);
- return $default;
- }
-
- public static function __callStatic($method, $parameters)
- {
- return call_user_func_array(array(static::driver(), $method), $parameters);
- }
- }
|