From 2f4d896958a39ee77a9bd2433dfd62882cf04999 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 14 Mar 2012 09:02:24 -0500 Subject: [PATCH] Added proper cache::forever implementations to each driver. Signed-off-by: Taylor Otwell --- laravel/cache/drivers/apc.php | 12 ++++++++++++ laravel/cache/drivers/database.php | 12 ++++++++++++ laravel/cache/drivers/driver.php | 12 ------------ laravel/cache/drivers/file.php | 12 ++++++++++++ laravel/cache/drivers/memcached.php | 12 ++++++++++++ laravel/cache/drivers/redis.php | 14 +++++++++++++- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/laravel/cache/drivers/apc.php b/laravel/cache/drivers/apc.php index 2852aee8..2fade423 100644 --- a/laravel/cache/drivers/apc.php +++ b/laravel/cache/drivers/apc.php @@ -63,6 +63,18 @@ class APC extends Driver { apc_store($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. * diff --git a/laravel/cache/drivers/database.php b/laravel/cache/drivers/database.php index 3edd18d1..3983e93c 100644 --- a/laravel/cache/drivers/database.php +++ b/laravel/cache/drivers/database.php @@ -87,6 +87,18 @@ class Database extends Driver { } } + /** + * Write an item to the cache for five years. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function forever($key, $value) + { + return $this->put($key, $value, 2628000); + } + /** * Delete an item from the cache. * diff --git a/laravel/cache/drivers/driver.php b/laravel/cache/drivers/driver.php index 01189749..b74ebe0a 100644 --- a/laravel/cache/drivers/driver.php +++ b/laravel/cache/drivers/driver.php @@ -53,18 +53,6 @@ abstract class Driver { */ abstract public function put($key, $value, $minutes); - /** - * Write an item to the cache for five years. - * - * @param string $key - * @param mixed $value - * @return void - */ - public function forever($key, $value) - { - return $this->put($key, $value, 2628000); - } - /** * Get an item from the cache, or cache and return the default value. * diff --git a/laravel/cache/drivers/file.php b/laravel/cache/drivers/file.php index dbf4520f..ee54aa3d 100644 --- a/laravel/cache/drivers/file.php +++ b/laravel/cache/drivers/file.php @@ -73,6 +73,18 @@ class File extends Driver { file_put_contents($this->path.$key, $value, LOCK_EX); } + /** + * Write an item to the cache for five years. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function forever($key, $value) + { + return $this->put($key, $value, 2628000); + } + /** * Delete an item from the cache. * diff --git a/laravel/cache/drivers/memcached.php b/laravel/cache/drivers/memcached.php index 08768927..4601e385 100644 --- a/laravel/cache/drivers/memcached.php +++ b/laravel/cache/drivers/memcached.php @@ -71,6 +71,18 @@ class Memcached extends Driver { $this->memcache->set($this->key.$key, $value, 0, $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. * diff --git a/laravel/cache/drivers/redis.php b/laravel/cache/drivers/redis.php index 2ed3cac6..3195566c 100644 --- a/laravel/cache/drivers/redis.php +++ b/laravel/cache/drivers/redis.php @@ -60,11 +60,23 @@ class Redis extends Driver { */ public function put($key, $value, $minutes) { - $this->redis->set($key, serialize($value)); + $this->forever($key, $value); $this->redis->expire($key, $minutes * 60); } + /** + * Write an item to the cache that lasts forever. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function forever($key, $value) + { + $this->redis->set($key, serialize($value)); + } + /** * Delete an item from the cache. *