From 117a4cb843640275368c52f0fc6567ecd4c1942f Mon Sep 17 00:00:00 2001 From: Bryan Wood Date: Wed, 26 Dec 2012 13:44:07 +1000 Subject: [PATCH] added wincache cache driver --- laravel/cache.php | 3 + laravel/cache/drivers/wincache.php | 89 ++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 laravel/cache/drivers/wincache.php diff --git a/laravel/cache.php b/laravel/cache.php index 02b86e4e..e633e83b 100644 --- a/laravel/cache.php +++ b/laravel/cache.php @@ -79,6 +79,9 @@ protected static function factory($driver) case 'database': return new Cache\Drivers\Database(Config::get('cache.key')); + case 'wincache': + return new Cache\Drivers\WinCache(Config::get('cache.key')); + default: throw new \Exception("Cache driver {$driver} is not supported."); } diff --git a/laravel/cache/drivers/wincache.php b/laravel/cache/drivers/wincache.php new file mode 100644 index 00000000..48f8ca03 --- /dev/null +++ b/laravel/cache/drivers/wincache.php @@ -0,0 +1,89 @@ +key = $key; + } + + /** + * Determine if an item exists in the cache. + * + * @param string $key + * @return bool + */ + public function has($key) + { + return ( ! is_null($this->get($key))); + } + + /** + * Retrieve an item from the cache driver. + * + * @param string $key + * @return mixed + */ + protected function retrieve($key) + { + if (($cache = wincache_ucache_get($this->key.$key)) !== false) + { + return $cache; + } + } + + /** + * Write an item to the cache for a given number of minutes. + * + * + * // Put an item in the cache for 15 minutes + * Cache::put('name', 'Taylor', 15); + * + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return void + */ + public function put($key, $value, $minutes) + { + wincache_ucache_add($this->key.$key, $value, $minutes * 60); + } + + /** + * Write an item to the cache that lasts forever. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function forever($key, $value) + { + return $this->put($key, $value, 0); + } + + /** + * Delete an item from the cache. + * + * @param string $key + * @return void + */ + public function forget($key) + { + wincache_ucache_delete($this->key.$key); + } + +} \ No newline at end of file