From 288781c0df3ca0ed98e425b34f0bce63d3fbccc5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 28 Sep 2011 22:55:48 -0500 Subject: [PATCH] added comments to cache classes. --- laravel/cache/drivers/driver.php | 22 ++++++++++++++++++++-- laravel/cache/drivers/file.php | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/laravel/cache/drivers/driver.php b/laravel/cache/drivers/driver.php index 3a622e61..7df279d0 100644 --- a/laravel/cache/drivers/driver.php +++ b/laravel/cache/drivers/driver.php @@ -15,8 +15,13 @@ abstract public function has($key); /** * Get an item from the cache. * - * A default value may also be specified, and will be returned in the requested - * item does not exist in the cache. + * + * // Get an item from the cache driver + * $name = Cache::driver('name'); + * + * // Return a default value if the requested item isn't cached + * $name = Cache::get('name', 'Taylor'); + * * * @param string $key * @param mixed $default @@ -41,6 +46,11 @@ abstract protected function retrieve($key); /** * 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 @@ -52,6 +62,14 @@ abstract public function put($key, $value, $minutes); * Get an item from the cache. If the item doesn't exist in the cache, store * the default value in the cache and return it. * + * + * // Get an item from the cache, or cache a value for 15 minutes if it doesn't exist + * $name = Cache::remember('name', 'Taylor', 15); + * + * // Use a closure for deferred execution + * $count = Cache::remember('count', function() { return User::count(); }, 15); + * + * * @param string $key * @param mixed $default * @param int $minutes diff --git a/laravel/cache/drivers/file.php b/laravel/cache/drivers/file.php index e99bb8fb..992f71c7 100644 --- a/laravel/cache/drivers/file.php +++ b/laravel/cache/drivers/file.php @@ -61,6 +61,7 @@ protected function retrieve($key) */ public function put($key, $value, $minutes) { + // The expiration time is stored as a UNIX timestamp at the beginning of the file. F::put($this->path.$key, (time() + ($minutes * 60)).serialize($value)); }