From ca58f80b227fc5adc9595bd78dce2a4e35b99217 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 9 Jul 2011 22:15:42 -0500 Subject: [PATCH] removed cache and session factories. moved cache item management into cache class and out of drivers. tweaked auth class. --- system/auth.php | 8 ++------ system/cache.php | 15 +++++++++++---- system/cache/driver/apc.php | 22 +++++---------------- system/cache/driver/file.php | 9 +-------- system/cache/driver/memcached.php | 22 +++++---------------- system/cache/factory.php | 29 ---------------------------- system/session/factory.php | 32 ------------------------------- 7 files changed, 24 insertions(+), 113 deletions(-) delete mode 100644 system/cache/factory.php delete mode 100644 system/session/factory.php diff --git a/system/auth.php b/system/auth.php index b06dcc7f..408930fd 100644 --- a/system/auth.php +++ b/system/auth.php @@ -40,11 +40,9 @@ public static function user() throw new \Exception("You must specify a session driver before using the Auth class."); } - $model = static::model(); - if (is_null(static::$user) and Session::has(static::$key)) { - static::$user = $model::find(Session::get(static::$key)); + static::$user = forward_static_call(array(static::model(), 'find'), Session::get(static::$key)); } return static::$user; @@ -61,9 +59,7 @@ public static function user() */ public static function login($username, $password) { - $model = static::model(); - - $user = $model::where(Config::get('auth.username'), '=', $username)->first(); + $model = forward_static_call(array(static::model(), 'where'), Config::get('auth.username'), '=', $username)->first(); if ( ! is_null($user)) { diff --git a/system/cache.php b/system/cache.php index 321f942c..fe2d2dc1 100644 --- a/system/cache.php +++ b/system/cache.php @@ -7,7 +7,14 @@ class Cache { * * @var Cache\Driver */ - private static $drivers = array(); + public static $drivers = array(); + + /** + * All of the items retrieved by the cache drivers. + * + * @var array + */ + public static $items = array(); /** * Get a cache driver instance. If no driver name is specified, the default @@ -59,9 +66,9 @@ public static function driver($driver = null) */ public static function get($key, $default = null, $driver = null) { - if (array_key_exists($key, static::driver($driver)->items)) + if (isset(static::$items[$driver][$key])) { - return static::driver($driver)->items[$key]; + return static::$items[$driver][$key]; } if (is_null($item = static::driver($driver)->get($key))) @@ -69,7 +76,7 @@ public static function get($key, $default = null, $driver = null) return is_callable($default) ? call_user_func($default) : $default; } - return $item; + return static::$items[$driver][$key] = $item; } /** diff --git a/system/cache/driver/apc.php b/system/cache/driver/apc.php index 978d995c..ba178634 100644 --- a/system/cache/driver/apc.php +++ b/system/cache/driver/apc.php @@ -1,13 +1,8 @@ items[$key] = $cache; + return ( ! is_null($cache = apc_fetch(Config::get('cache.key').$key))) ? $cache : null; } /** @@ -48,7 +36,7 @@ public function get($key) */ public function put($key, $value, $minutes) { - apc_store(\System\Config::get('cache.key').$key, $value, $minutes * 60); + apc_store(Config::get('cache.key').$key, $value, $minutes * 60); } /** @@ -59,7 +47,7 @@ public function put($key, $value, $minutes) */ public function forget($key) { - apc_delete(\System\Config::get('cache.key').$key); + apc_delete(Config::get('cache.key').$key); } } \ No newline at end of file diff --git a/system/cache/driver/file.php b/system/cache/driver/file.php index 3de5ba4f..442f1cfd 100644 --- a/system/cache/driver/file.php +++ b/system/cache/driver/file.php @@ -2,13 +2,6 @@ class File implements \System\Cache\Driver { - /** - * All of the loaded cache items. - * - * @var array - */ - public $items = array(); - /** * Determine if an item exists in the cache. * @@ -43,7 +36,7 @@ public function get($key) return null; } - return $this->items[$key] = unserialize(substr($cache, 10)); + return unserialize(substr($cache, 10)); } /** diff --git a/system/cache/driver/memcached.php b/system/cache/driver/memcached.php index 2710ea78..c2f4fe06 100644 --- a/system/cache/driver/memcached.php +++ b/system/cache/driver/memcached.php @@ -1,13 +1,8 @@ get(\System\Config::get('cache.key').$key); - - if ($cache === false) - { - return null; - } - - return $this->items[$key] = $cache; + return (($cache = \System\Memcached::instance()->get(Config::get('cache.key').$key)) !== false) ? $cache : null; } /** @@ -48,7 +36,7 @@ public function get($key) */ public function put($key, $value, $minutes) { - \System\Memcached::instance()->set(\System\Config::get('cache.key').$key, $value, 0, $minutes * 60); + \System\Memcached::instance()->set(Config::get('cache.key').$key, $value, 0, $minutes * 60); } /** @@ -59,7 +47,7 @@ public function put($key, $value, $minutes) */ public function forget($key) { - \System\Memcached::instance()->delete(\System\Config::get('cache.key').$key); + \System\Memcached::instance()->delete(Config::get('cache.key').$key); } } \ No newline at end of file diff --git a/system/cache/factory.php b/system/cache/factory.php deleted file mode 100644 index 245f4c85..00000000 --- a/system/cache/factory.php +++ /dev/null @@ -1,29 +0,0 @@ -