1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php namespace Laravel\Cache;
- abstract class Driver {
- /**
- * Determine if an item exists in the cache.
- *
- * @param string $key
- * @return bool
- */
- 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.
- *
- * @param string $key
- * @param mixed $default
- * @param string $driver
- * @return mixed
- */
- public function get($key, $default = null)
- {
- if ( ! is_null($item = $this->retrieve($key))) return $item;
- return ($default instanceof \Closure) ? call_user_func($default) : $default;
- }
- /**
- * Retrieve an item from the cache driver.
- *
- * @param string $key
- * @return mixed
- */
- abstract protected function retrieve($key);
- /**
- * Write an item to the cache for a given number of minutes.
- *
- * @param string $key
- * @param mixed $value
- * @param int $minutes
- * @return void
- */
- 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.
- *
- * @param string $key
- * @param mixed $default
- * @param int $minutes
- * @return mixed
- */
- public function remember($key, $value, $minutes)
- {
- if ( ! is_null($item = $this->get($key, null))) return $item;
- $default = ($default instanceof \Closure) ? call_user_func($default) : $default;
- $this->put($key, $default, $minutes);
- return $default;
- }
- /**
- * Delete an item from the cache.
- *
- * @param string $key
- * @return void
- */
- abstract public function forget($key);
- }
|