update v 1.0.7.5
This commit is contained in:
@@ -1,130 +1,132 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class ApcStore extends TaggableStore implements Store {
|
||||
class ApcStore extends TaggableStore implements Store
|
||||
{
|
||||
use RetrievesMultipleKeys;
|
||||
|
||||
/**
|
||||
* The APC wrapper instance.
|
||||
*
|
||||
* @var \Illuminate\Cache\ApcWrapper
|
||||
*/
|
||||
protected $apc;
|
||||
/**
|
||||
* The APC wrapper instance.
|
||||
*
|
||||
* @var \Illuminate\Cache\ApcWrapper
|
||||
*/
|
||||
protected $apc;
|
||||
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* Create a new APC store.
|
||||
*
|
||||
* @param \Illuminate\Cache\ApcWrapper $apc
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ApcWrapper $apc, $prefix = '')
|
||||
{
|
||||
$this->apc = $apc;
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
/**
|
||||
* Create a new APC store.
|
||||
*
|
||||
* @param \Illuminate\Cache\ApcWrapper $apc
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ApcWrapper $apc, $prefix = '')
|
||||
{
|
||||
$this->apc = $apc;
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = $this->apc->get($this->prefix.$key);
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = $this->apc->get($this->prefix.$key);
|
||||
|
||||
if ($value !== false)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
if ($value !== false) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->apc->put($this->prefix.$key, $value, $minutes * 60);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->apc->put($this->prefix.$key, $value, $minutes * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return $this->apc->increment($this->prefix.$key, $value);
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return $this->apc->increment($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->apc->decrement($this->prefix.$key, $value);
|
||||
}
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->apc->decrement($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return array|bool
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
return $this->put($key, $value, 0);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return $this->apc->delete($this->prefix.$key);
|
||||
}
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return $this->apc->delete($this->prefix.$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->apc->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->apc->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,91 +1,92 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
class ApcWrapper {
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
/**
|
||||
* Indicates if APCu is supported.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $apcu = false;
|
||||
class ApcWrapper
|
||||
{
|
||||
/**
|
||||
* Indicates if APCu is supported.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $apcu = false;
|
||||
|
||||
/**
|
||||
* Create a new APC wrapper instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->apcu = function_exists('apcu_fetch');
|
||||
}
|
||||
/**
|
||||
* Create a new APC wrapper instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->apcu = function_exists('apcu_fetch');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return $this->apcu ? apcu_fetch($key) : apc_fetch($key);
|
||||
}
|
||||
/**
|
||||
* Get an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return $this->apcu ? apcu_fetch($key) : apc_fetch($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $seconds
|
||||
* @return array|bool
|
||||
*/
|
||||
public function put($key, $value, $seconds)
|
||||
{
|
||||
return $this->apcu ? apcu_store($key, $value, $seconds) : apc_store($key, $value, $seconds);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $seconds
|
||||
* @return array|bool
|
||||
*/
|
||||
public function put($key, $value, $seconds)
|
||||
{
|
||||
return $this->apcu ? apcu_store($key, $value, $seconds) : apc_store($key, $value, $seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function increment($key, $value)
|
||||
{
|
||||
return $this->apcu ? apcu_inc($key, $value) : apc_inc($key, $value);
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function increment($key, $value)
|
||||
{
|
||||
return $this->apcu ? apcu_inc($key, $value) : apc_inc($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function decrement($key, $value)
|
||||
{
|
||||
return $this->apcu ? apcu_dec($key, $value) : apc_dec($key, $value);
|
||||
}
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function decrement($key, $value)
|
||||
{
|
||||
return $this->apcu ? apcu_dec($key, $value) : apc_dec($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
return $this->apcu ? apcu_delete($key) : apc_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->apcu ? apcu_clear_cache() : apc_clear_cache('user');
|
||||
}
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
return $this->apcu ? apcu_delete($key) : apc_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->apcu ? apcu_clear_cache() : apc_clear_cache('user');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,112 +1,114 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class ArrayStore extends TaggableStore implements Store {
|
||||
class ArrayStore extends TaggableStore implements Store
|
||||
{
|
||||
use RetrievesMultipleKeys;
|
||||
|
||||
/**
|
||||
* The array of stored values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $storage = array();
|
||||
/**
|
||||
* The array of stored values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $storage = [];
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (array_key_exists($key, $this->storage))
|
||||
{
|
||||
return $this->storage[$key];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (array_key_exists($key, $this->storage)) {
|
||||
return $this->storage[$key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->storage[$key] = $value;
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->storage[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
$this->storage[$key] = $this->storage[$key] + $value;
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
$this->storage[$key] = $this->storage[$key] + $value;
|
||||
|
||||
return $this->storage[$key];
|
||||
}
|
||||
return $this->storage[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->increment($key, $value * -1);
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->increment($key, $value * -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 0);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
unset($this->storage[$key]);
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
unset($this->storage[$key]);
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->storage = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->storage = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,315 +1,298 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
use Illuminate\Contracts\Cache\Factory as FactoryContract;
|
||||
|
||||
class CacheManager implements FactoryContract {
|
||||
class CacheManager implements FactoryContract
|
||||
{
|
||||
/**
|
||||
* The application instance.
|
||||
*
|
||||
* @var \Illuminate\Foundation\Application
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* The application instance.
|
||||
*
|
||||
* @var \Illuminate\Foundation\Application
|
||||
*/
|
||||
protected $app;
|
||||
/**
|
||||
* The array of resolved cache stores.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $stores = [];
|
||||
|
||||
/**
|
||||
* The array of resolved cache stores.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $stores = [];
|
||||
/**
|
||||
* The registered custom driver creators.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $customCreators = [];
|
||||
|
||||
/**
|
||||
* The registered custom driver creators.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $customCreators = [];
|
||||
/**
|
||||
* Create a new Cache manager instance.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Cache manager instance.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
/**
|
||||
* Get a cache store instance by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($name = null)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultDriver();
|
||||
|
||||
/**
|
||||
* Get a cache store instance by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function store($name = null)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultDriver();
|
||||
return $this->stores[$name] = $this->get($name);
|
||||
}
|
||||
|
||||
return $this->stores[$name] = $this->get($name);
|
||||
}
|
||||
/**
|
||||
* Get a cache driver instance.
|
||||
*
|
||||
* @param string $driver
|
||||
* @return mixed
|
||||
*/
|
||||
public function driver($driver = null)
|
||||
{
|
||||
return $this->store($driver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a cache driver instance.
|
||||
*
|
||||
* @param string $driver
|
||||
* @return mixed
|
||||
*/
|
||||
public function driver($driver = null)
|
||||
{
|
||||
return $this->store($driver);
|
||||
}
|
||||
/**
|
||||
* Attempt to get the store from the local cache.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected function get($name)
|
||||
{
|
||||
return isset($this->stores[$name]) ? $this->stores[$name] : $this->resolve($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to get the store from the local cache.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected function get($name)
|
||||
{
|
||||
return isset($this->stores[$name]) ? $this->stores[$name] : $this->resolve($name);
|
||||
}
|
||||
/**
|
||||
* Resolve the given store.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Contracts\Cache\Repository
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function resolve($name)
|
||||
{
|
||||
$config = $this->getConfig($name);
|
||||
|
||||
/**
|
||||
* Resolve the given store.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected function resolve($name)
|
||||
{
|
||||
$config = $this->getConfig($name);
|
||||
if (is_null($config)) {
|
||||
throw new InvalidArgumentException("Cache store [{$name}] is not defined.");
|
||||
}
|
||||
|
||||
if (is_null($config))
|
||||
{
|
||||
throw new InvalidArgumentException("Cache store [{$name}] is not defined.");
|
||||
}
|
||||
if (isset($this->customCreators[$config['driver']])) {
|
||||
return $this->callCustomCreator($config);
|
||||
} else {
|
||||
$driverMethod = 'create'.ucfirst($config['driver']).'Driver';
|
||||
|
||||
if (isset($this->customCreators[$config['driver']]))
|
||||
{
|
||||
return $this->callCustomCreator($config);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->{"create".ucfirst($config['driver'])."Driver"}($config);
|
||||
}
|
||||
}
|
||||
if (method_exists($this, $driverMethod)) {
|
||||
return $this->{$driverMethod}($config);
|
||||
} else {
|
||||
throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a custom driver creator.
|
||||
*
|
||||
* @param array $config
|
||||
* @return mixed
|
||||
*/
|
||||
protected function callCustomCreator(array $config)
|
||||
{
|
||||
return $this->customCreators[$config['driver']]($this->app, $config);
|
||||
}
|
||||
/**
|
||||
* Call a custom driver creator.
|
||||
*
|
||||
* @param array $config
|
||||
* @return mixed
|
||||
*/
|
||||
protected function callCustomCreator(array $config)
|
||||
{
|
||||
return $this->customCreators[$config['driver']]($this->app, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the APC cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\ApcStore
|
||||
*/
|
||||
protected function createApcDriver(array $config)
|
||||
{
|
||||
$prefix = $this->getPrefix($config);
|
||||
/**
|
||||
* Create an instance of the APC cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\ApcStore
|
||||
*/
|
||||
protected function createApcDriver(array $config)
|
||||
{
|
||||
$prefix = $this->getPrefix($config);
|
||||
|
||||
return $this->repository(new ApcStore(new ApcWrapper, $prefix));
|
||||
}
|
||||
return $this->repository(new ApcStore(new ApcWrapper, $prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the array cache driver.
|
||||
*
|
||||
* @return \Illuminate\Cache\ArrayStore
|
||||
*/
|
||||
protected function createArrayDriver()
|
||||
{
|
||||
return $this->repository(new ArrayStore);
|
||||
}
|
||||
/**
|
||||
* Create an instance of the array cache driver.
|
||||
*
|
||||
* @return \Illuminate\Cache\ArrayStore
|
||||
*/
|
||||
protected function createArrayDriver()
|
||||
{
|
||||
return $this->repository(new ArrayStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the file cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\FileStore
|
||||
*/
|
||||
protected function createFileDriver(array $config)
|
||||
{
|
||||
return $this->repository(new FileStore($this->app['files'], $config['path']));
|
||||
}
|
||||
/**
|
||||
* Create an instance of the file cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\FileStore
|
||||
*/
|
||||
protected function createFileDriver(array $config)
|
||||
{
|
||||
return $this->repository(new FileStore($this->app['files'], $config['path']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the Memcached cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\MemcachedStore
|
||||
*/
|
||||
protected function createMemcachedDriver(array $config)
|
||||
{
|
||||
$prefix = $this->getPrefix($config);
|
||||
/**
|
||||
* Create an instance of the Memcached cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\MemcachedStore
|
||||
*/
|
||||
protected function createMemcachedDriver(array $config)
|
||||
{
|
||||
$prefix = $this->getPrefix($config);
|
||||
|
||||
$memcached = $this->app['memcached.connector']->connect($config['servers']);
|
||||
$memcached = $this->app['memcached.connector']->connect($config['servers']);
|
||||
|
||||
return $this->repository(new MemcachedStore($memcached, $prefix));
|
||||
}
|
||||
return $this->repository(new MemcachedStore($memcached, $prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the Null cache driver.
|
||||
*
|
||||
* @return \Illuminate\Cache\NullStore
|
||||
*/
|
||||
protected function createNullDriver()
|
||||
{
|
||||
return $this->repository(new NullStore);
|
||||
}
|
||||
/**
|
||||
* Create an instance of the Null cache driver.
|
||||
*
|
||||
* @return \Illuminate\Cache\NullStore
|
||||
*/
|
||||
protected function createNullDriver()
|
||||
{
|
||||
return $this->repository(new NullStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the WinCache cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\WinCacheStore
|
||||
*/
|
||||
protected function createWincacheDriver(array $config)
|
||||
{
|
||||
return $this->repository(new WinCacheStore($this->getPrefix($config)));
|
||||
}
|
||||
/**
|
||||
* Create an instance of the Redis cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\RedisStore
|
||||
*/
|
||||
protected function createRedisDriver(array $config)
|
||||
{
|
||||
$redis = $this->app['redis'];
|
||||
|
||||
/**
|
||||
* Create an instance of the XCache cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\WinCacheStore
|
||||
*/
|
||||
protected function createXcacheDriver(array $config)
|
||||
{
|
||||
return $this->repository(new XCacheStore($this->getPrefix($config)));
|
||||
}
|
||||
$connection = Arr::get($config, 'connection', 'default');
|
||||
|
||||
/**
|
||||
* Create an instance of the Redis cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\RedisStore
|
||||
*/
|
||||
protected function createRedisDriver(array $config)
|
||||
{
|
||||
$redis = $this->app['redis'];
|
||||
return $this->repository(new RedisStore($redis, $this->getPrefix($config), $connection));
|
||||
}
|
||||
|
||||
$connection = array_get($config, 'connection', 'default') ?: 'default';
|
||||
/**
|
||||
* Create an instance of the database cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\DatabaseStore
|
||||
*/
|
||||
protected function createDatabaseDriver(array $config)
|
||||
{
|
||||
$connection = $this->app['db']->connection(Arr::get($config, 'connection'));
|
||||
|
||||
return $this->repository(new RedisStore($redis, $this->getPrefix($config), $connection));
|
||||
}
|
||||
return $this->repository(
|
||||
new DatabaseStore(
|
||||
$connection, $this->app['encrypter'], $config['table'], $this->getPrefix($config)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the database cache driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Cache\DatabaseStore
|
||||
*/
|
||||
protected function createDatabaseDriver(array $config)
|
||||
{
|
||||
$connection = $this->app['db']->connection(array_get($config, 'connection'));
|
||||
/**
|
||||
* Create a new cache repository with the given implementation.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Store $store
|
||||
* @return \Illuminate\Cache\Repository
|
||||
*/
|
||||
public function repository(Store $store)
|
||||
{
|
||||
$repository = new Repository($store);
|
||||
|
||||
return $this->repository(
|
||||
new DatabaseStore(
|
||||
$connection, $this->app['encrypter'], $config['table'], $this->getPrefix($config)
|
||||
)
|
||||
);
|
||||
}
|
||||
if ($this->app->bound('Illuminate\Contracts\Events\Dispatcher')) {
|
||||
$repository->setEventDispatcher(
|
||||
$this->app['Illuminate\Contracts\Events\Dispatcher']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new cache repository with the given implementation.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Store $store
|
||||
* @return \Illuminate\Cache\Repository
|
||||
*/
|
||||
public function repository(Store $store)
|
||||
{
|
||||
$repository = new Repository($store);
|
||||
return $repository;
|
||||
}
|
||||
|
||||
if ($this->app->bound('Illuminate\Contracts\Events\Dispatcher'))
|
||||
{
|
||||
$repository->setEventDispatcher(
|
||||
$this->app['Illuminate\Contracts\Events\Dispatcher']
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Get the cache prefix.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getPrefix(array $config)
|
||||
{
|
||||
return Arr::get($config, 'prefix') ?: $this->app['config']['cache.prefix'];
|
||||
}
|
||||
|
||||
return $repository;
|
||||
}
|
||||
/**
|
||||
* Get the cache connection configuration.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function getConfig($name)
|
||||
{
|
||||
return $this->app['config']["cache.stores.{$name}"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache prefix.
|
||||
*
|
||||
* @param array $config
|
||||
* @return string
|
||||
*/
|
||||
protected function getPrefix(array $config)
|
||||
{
|
||||
return array_get($config, 'prefix') ?: $this->app['config']['cache.prefix'];
|
||||
}
|
||||
/**
|
||||
* Get the default cache driver name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultDriver()
|
||||
{
|
||||
return $this->app['config']['cache.default'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache connection configuration.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function getConfig($name)
|
||||
{
|
||||
return $this->app['config']["cache.stores.{$name}"];
|
||||
}
|
||||
/**
|
||||
* Set the default cache driver name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultDriver($name)
|
||||
{
|
||||
$this->app['config']['cache.default'] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default cache driver name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultDriver()
|
||||
{
|
||||
return $this->app['config']['cache.default'];
|
||||
}
|
||||
/**
|
||||
* Register a custom driver creator Closure.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function extend($driver, Closure $callback)
|
||||
{
|
||||
$this->customCreators[$driver] = $callback;
|
||||
|
||||
/**
|
||||
* Set the default cache driver name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultDriver($name)
|
||||
{
|
||||
$this->app['config']['cache.default'] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a custom driver creator Closure.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function extend($driver, Closure $callback)
|
||||
{
|
||||
$this->customCreators[$driver] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically call the default driver instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return call_user_func_array(array($this->store(), $method), $parameters);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically call the default driver instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return call_user_func_array([$this->store(), $method], $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,64 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Cache\Console\ClearCommand;
|
||||
use Illuminate\Cache\Console\CacheTableCommand;
|
||||
|
||||
class CacheServiceProvider extends ServiceProvider {
|
||||
class CacheServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('cache', function ($app) {
|
||||
return new CacheManager($app);
|
||||
});
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('cache', function($app)
|
||||
{
|
||||
return new CacheManager($app);
|
||||
});
|
||||
$this->app->singleton('cache.store', function ($app) {
|
||||
return $app['cache']->driver();
|
||||
});
|
||||
|
||||
$this->app->singleton('cache.store', function($app)
|
||||
{
|
||||
return $app['cache']->driver();
|
||||
});
|
||||
$this->app->singleton('memcached.connector', function () {
|
||||
return new MemcachedConnector;
|
||||
});
|
||||
|
||||
$this->app->singleton('memcached.connector', function()
|
||||
{
|
||||
return new MemcachedConnector;
|
||||
});
|
||||
$this->registerCommands();
|
||||
}
|
||||
|
||||
$this->registerCommands();
|
||||
}
|
||||
/**
|
||||
* Register the cache related console commands.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerCommands()
|
||||
{
|
||||
$this->app->singleton('command.cache.clear', function ($app) {
|
||||
return new ClearCommand($app['cache']);
|
||||
});
|
||||
|
||||
/**
|
||||
* Register the cache related console commands.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerCommands()
|
||||
{
|
||||
$this->app->singleton('command.cache.clear', function($app)
|
||||
{
|
||||
return new ClearCommand($app['cache']);
|
||||
});
|
||||
|
||||
$this->app->singleton('command.cache.table', function($app)
|
||||
{
|
||||
return new CacheTableCommand($app['files'], $app['composer']);
|
||||
});
|
||||
|
||||
$this->commands('command.cache.clear', 'command.cache.table');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [
|
||||
'cache', 'cache.store', 'memcached.connector', 'command.cache.clear', 'command.cache.table',
|
||||
];
|
||||
}
|
||||
$this->commands('command.cache.clear');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [
|
||||
'cache', 'cache.store', 'memcached.connector', 'command.cache.clear',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,81 @@
|
||||
<?php namespace Illuminate\Cache\Console;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Composer;
|
||||
use Illuminate\Support\Composer;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class CacheTableCommand extends Command {
|
||||
class CacheTableCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'cache:table';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'cache:table';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a migration for the cache database table';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a migration for the cache database table';
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
/**
|
||||
* @var \Illuminate\Support\Composer
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Foundation\Composer
|
||||
*/
|
||||
protected $composer;
|
||||
/**
|
||||
* Create a new session table command instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param \Illuminate\Support\Composer $composer
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files, Composer $composer)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
/**
|
||||
* Create a new session table command instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param \Illuminate\Foundation\Composer $composer
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files, Composer $composer)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->files = $files;
|
||||
$this->composer = $composer;
|
||||
}
|
||||
|
||||
$this->files = $files;
|
||||
$this->composer = $composer;
|
||||
}
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$fullPath = $this->createBaseMigration();
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$fullPath = $this->createBaseMigration();
|
||||
$this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/cache.stub'));
|
||||
|
||||
$this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/cache.stub'));
|
||||
$this->info('Migration created successfully!');
|
||||
|
||||
$this->info('Migration created successfully!');
|
||||
$this->composer->dumpAutoloads();
|
||||
}
|
||||
|
||||
$this->composer->dumpAutoloads();
|
||||
}
|
||||
/**
|
||||
* Create a base migration file for the table.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createBaseMigration()
|
||||
{
|
||||
$name = 'create_cache_table';
|
||||
|
||||
/**
|
||||
* Create a base migration file for the table.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createBaseMigration()
|
||||
{
|
||||
$name = 'create_cache_table';
|
||||
|
||||
$path = $this->laravel->databasePath().'/migrations';
|
||||
|
||||
return $this->laravel['migration.creator']->create($name, $path);
|
||||
}
|
||||
$path = $this->laravel->databasePath().'/migrations';
|
||||
|
||||
return $this->laravel['migration.creator']->create($name, $path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,74 @@
|
||||
<?php namespace Illuminate\Cache\Console;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Cache\CacheManager;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class ClearCommand extends Command {
|
||||
class ClearCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'cache:clear';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'cache:clear';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Flush the application cache';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = "Flush the application cache";
|
||||
/**
|
||||
* The cache manager instance.
|
||||
*
|
||||
* @var \Illuminate\Cache\CacheManager
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* The cache manager instance.
|
||||
*
|
||||
* @var \Illuminate\Cache\CacheManager
|
||||
*/
|
||||
protected $cache;
|
||||
/**
|
||||
* Create a new cache clear command instance.
|
||||
*
|
||||
* @param \Illuminate\Cache\CacheManager $cache
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CacheManager $cache)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
/**
|
||||
* Create a new cache clear command instance.
|
||||
*
|
||||
* @param \Illuminate\Cache\CacheManager $cache
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CacheManager $cache)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
$this->cache = $cache;
|
||||
}
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$storeName = $this->argument('store');
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$storeName = $this->argument('store');
|
||||
$this->laravel['events']->fire('cache:clearing', [$storeName]);
|
||||
|
||||
$this->laravel['events']->fire('cache:clearing', [$storeName]);
|
||||
$this->cache->store($storeName)->flush();
|
||||
|
||||
$this->cache->store($storeName)->flush();
|
||||
$this->laravel['events']->fire('cache:cleared', [$storeName]);
|
||||
|
||||
$this->laravel['events']->fire('cache:cleared', [$storeName]);
|
||||
|
||||
$this->info('Application cache cleared!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['store', InputArgument::OPTIONAL, 'The name of the store you would like to clear.'],
|
||||
];
|
||||
}
|
||||
$this->info('Application cache cleared!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['store', InputArgument::OPTIONAL, 'The name of the store you would like to clear.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,31 +3,29 @@
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCacheTable extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cache', function(Blueprint $table)
|
||||
{
|
||||
$table->string('key')->unique();
|
||||
$table->text('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('cache');
|
||||
}
|
||||
class CreateCacheTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->unique();
|
||||
$table->text('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('cache');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,228 +1,266 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use LogicException;
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
|
||||
|
||||
class DatabaseStore implements Store {
|
||||
class DatabaseStore implements Store
|
||||
{
|
||||
use RetrievesMultipleKeys;
|
||||
|
||||
/**
|
||||
* The database connection instance.
|
||||
*
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
/**
|
||||
* The database connection instance.
|
||||
*
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The encrypter instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
protected $encrypter;
|
||||
/**
|
||||
* The encrypter instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
protected $encrypter;
|
||||
|
||||
/**
|
||||
* The name of the cache table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
/**
|
||||
* The name of the cache table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* Create a new database store.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
|
||||
* @param string $table
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ConnectionInterface $connection, EncrypterContract $encrypter, $table, $prefix = '')
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->prefix = $prefix;
|
||||
$this->encrypter = $encrypter;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
/**
|
||||
* Create a new database store.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
|
||||
* @param string $table
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ConnectionInterface $connection, EncrypterContract $encrypter, $table, $prefix = '')
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->prefix = $prefix;
|
||||
$this->encrypter = $encrypter;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$prefixed = $this->prefix.$key;
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$prefixed = $this->prefix.$key;
|
||||
|
||||
$cache = $this->table()->where('key', '=', $prefixed)->first();
|
||||
$cache = $this->table()->where('key', '=', $prefixed)->first();
|
||||
|
||||
// If we have a cache record we will check the expiration time against current
|
||||
// time on the system and see if the record has expired. If it has, we will
|
||||
// remove the records from the database table so it isn't returned again.
|
||||
if ( ! is_null($cache))
|
||||
{
|
||||
if (is_array($cache)) $cache = (object) $cache;
|
||||
// If we have a cache record we will check the expiration time against current
|
||||
// time on the system and see if the record has expired. If it has, we will
|
||||
// remove the records from the database table so it isn't returned again.
|
||||
if (! is_null($cache)) {
|
||||
if (is_array($cache)) {
|
||||
$cache = (object) $cache;
|
||||
}
|
||||
|
||||
if (time() >= $cache->expiration)
|
||||
{
|
||||
$this->forget($key);
|
||||
if (time() >= $cache->expiration) {
|
||||
$this->forget($key);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->encrypter->decrypt($cache->value);
|
||||
}
|
||||
}
|
||||
return $this->encrypter->decrypt($cache->value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$key = $this->prefix.$key;
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$key = $this->prefix.$key;
|
||||
|
||||
// All of the cached values in the database are encrypted in case this is used
|
||||
// as a session data store by the consumer. We'll also calculate the expire
|
||||
// time and place that on the table so we will check it on our retrieval.
|
||||
$value = $this->encrypter->encrypt($value);
|
||||
// All of the cached values in the database are encrypted in case this is used
|
||||
// as a session data store by the consumer. We'll also calculate the expire
|
||||
// time and place that on the table so we will check it on our retrieval.
|
||||
$value = $this->encrypter->encrypt($value);
|
||||
|
||||
$expiration = $this->getTime() + ($minutes * 60);
|
||||
$expiration = $this->getTime() + ($minutes * 60);
|
||||
|
||||
try
|
||||
{
|
||||
$this->table()->insert(compact('key', 'value', 'expiration'));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->table()->where('key', '=', $key)->update(compact('value', 'expiration'));
|
||||
}
|
||||
}
|
||||
try {
|
||||
$this->table()->insert(compact('key', 'value', 'expiration'));
|
||||
} catch (Exception $e) {
|
||||
$this->table()->where('key', '=', $key)->update(compact('value', 'expiration'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
throw new LogicException("Increment operations not supported by this driver.");
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return $this->incrementOrDecrement($key, $value, function ($current, $value) {
|
||||
return $current + $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
throw new LogicException("Decrement operations not supported by this driver.");
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->incrementOrDecrement($key, $value, function ($current, $value) {
|
||||
return $current - $value;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current system time.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getTime()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
/**
|
||||
* Increment or decrement an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param \Closure $callback
|
||||
* @return int|bool
|
||||
*/
|
||||
protected function incrementOrDecrement($key, $value, Closure $callback)
|
||||
{
|
||||
return $this->connection->transaction(function () use ($key, $value, $callback) {
|
||||
$prefixed = $this->prefix.$key;
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 5256000);
|
||||
}
|
||||
$cache = $this->table()->where('key', $prefixed)->lockForUpdate()->first();
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$this->table()->where('key', '=', $this->prefix.$key)->delete();
|
||||
if (is_null($cache)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
if (is_array($cache)) {
|
||||
$cache = (object) $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->table()->delete();
|
||||
}
|
||||
$current = $this->encrypter->decrypt($cache->value);
|
||||
$new = $callback($current, $value);
|
||||
|
||||
/**
|
||||
* Get a query builder for the cache table.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function table()
|
||||
{
|
||||
return $this->connection->table($this->table);
|
||||
}
|
||||
if (! is_numeric($current)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying database connection.
|
||||
*
|
||||
* @return \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
$this->table()->where('key', $prefixed)->update([
|
||||
'value' => $this->encrypter->encrypt($new),
|
||||
]);
|
||||
|
||||
/**
|
||||
* Get the encrypter instance.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
public function getEncrypter()
|
||||
{
|
||||
return $this->encrypter;
|
||||
}
|
||||
return $new;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
/**
|
||||
* Get the current system time.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getTime()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 5256000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$this->table()->where('key', '=', $this->prefix.$key)->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->table()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a query builder for the cache table.
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
protected function table()
|
||||
{
|
||||
return $this->connection->table($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying database connection.
|
||||
*
|
||||
* @return \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the encrypter instance.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
public function getEncrypter()
|
||||
{
|
||||
return $this->encrypter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
}
|
||||
|
||||
42
vendor/laravel/framework/src/Illuminate/Cache/Events/CacheHit.php
vendored
Normal file
42
vendor/laravel/framework/src/Illuminate/Cache/Events/CacheHit.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache\Events;
|
||||
|
||||
class CacheHit
|
||||
{
|
||||
/**
|
||||
* The key that was hit.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $key;
|
||||
|
||||
/**
|
||||
* The value that was retrieved.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* The tags that were assigned to the key.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $tags;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $tags
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($key, $value, array $tags = [])
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->tags = $tags;
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
33
vendor/laravel/framework/src/Illuminate/Cache/Events/CacheMissed.php
vendored
Normal file
33
vendor/laravel/framework/src/Illuminate/Cache/Events/CacheMissed.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache\Events;
|
||||
|
||||
class CacheMissed
|
||||
{
|
||||
/**
|
||||
* THe key that was missed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $key;
|
||||
|
||||
/**
|
||||
* The tags that were assigned to the key.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $tags;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $key
|
||||
* @param array $tags
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($key, array $tags = [])
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->tags = $tags;
|
||||
}
|
||||
}
|
||||
33
vendor/laravel/framework/src/Illuminate/Cache/Events/KeyForgotten.php
vendored
Normal file
33
vendor/laravel/framework/src/Illuminate/Cache/Events/KeyForgotten.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache\Events;
|
||||
|
||||
class KeyForgotten
|
||||
{
|
||||
/**
|
||||
* The key that was forgotten.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $key;
|
||||
|
||||
/**
|
||||
* The tags that were assigned to the key.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $tags;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $key
|
||||
* @param array $tags
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($key, $tags = [])
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->tags = $tags;
|
||||
}
|
||||
}
|
||||
51
vendor/laravel/framework/src/Illuminate/Cache/Events/KeyWritten.php
vendored
Normal file
51
vendor/laravel/framework/src/Illuminate/Cache/Events/KeyWritten.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache\Events;
|
||||
|
||||
class KeyWritten
|
||||
{
|
||||
/**
|
||||
* The key that was written.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $key;
|
||||
|
||||
/**
|
||||
* The value that was written.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* The number of minutes the key should be valid.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $minutes;
|
||||
|
||||
/**
|
||||
* The tags that were assigned to the key.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $tags;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @param array $tags
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($key, $value, $minutes, $tags = [])
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->tags = $tags;
|
||||
$this->value = $value;
|
||||
$this->minutes = $minutes;
|
||||
}
|
||||
}
|
||||
@@ -1,256 +1,254 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class FileStore implements Store {
|
||||
class FileStore implements Store
|
||||
{
|
||||
use RetrievesMultipleKeys;
|
||||
|
||||
/**
|
||||
* The Illuminate Filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
/**
|
||||
* The Illuminate Filesystem instance.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* The file cache directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $directory;
|
||||
/**
|
||||
* The file cache directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* Create a new file cache store instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param string $directory
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files, $directory)
|
||||
{
|
||||
$this->files = $files;
|
||||
$this->directory = $directory;
|
||||
}
|
||||
/**
|
||||
* Create a new file cache store instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $files
|
||||
* @param string $directory
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Filesystem $files, $directory)
|
||||
{
|
||||
$this->files = $files;
|
||||
$this->directory = $directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return array_get($this->getPayload($key), 'data');
|
||||
}
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return Arr::get($this->getPayload($key), 'data');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item and expiry time from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
protected function getPayload($key)
|
||||
{
|
||||
$path = $this->path($key);
|
||||
/**
|
||||
* Retrieve an item and expiry time from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
protected function getPayload($key)
|
||||
{
|
||||
$path = $this->path($key);
|
||||
|
||||
// If the file doesn't exists, we obviously can't return the cache so we will
|
||||
// just return null. Otherwise, we'll get the contents of the file and get
|
||||
// the expiration UNIX timestamps from the start of the file's contents.
|
||||
try
|
||||
{
|
||||
$expire = substr($contents = $this->files->get($path), 0, 10);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return array('data' => null, 'time' => null);
|
||||
}
|
||||
// If the file doesn't exists, we obviously can't return the cache so we will
|
||||
// just return null. Otherwise, we'll get the contents of the file and get
|
||||
// the expiration UNIX timestamps from the start of the file's contents.
|
||||
try {
|
||||
$expire = substr(
|
||||
$contents = $this->files->get($path, true), 0, 10
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return ['data' => null, 'time' => null];
|
||||
}
|
||||
|
||||
// If the current time is greater than expiration timestamps we will delete
|
||||
// the file and return null. This helps clean up the old files and keeps
|
||||
// this directory much cleaner for us as old files aren't hanging out.
|
||||
if (time() >= $expire)
|
||||
{
|
||||
$this->forget($key);
|
||||
// If the current time is greater than expiration timestamps we will delete
|
||||
// the file and return null. This helps clean up the old files and keeps
|
||||
// this directory much cleaner for us as old files aren't hanging out.
|
||||
if (time() >= $expire) {
|
||||
$this->forget($key);
|
||||
|
||||
return array('data' => null, 'time' => null);
|
||||
}
|
||||
return ['data' => null, 'time' => null];
|
||||
}
|
||||
|
||||
$data = unserialize(substr($contents, 10));
|
||||
$data = unserialize(substr($contents, 10));
|
||||
|
||||
// Next, we'll extract the number of minutes that are remaining for a cache
|
||||
// so that we can properly retain the time for things like the increment
|
||||
// operation that may be performed on the cache. We'll round this out.
|
||||
$time = ceil(($expire - time()) / 60);
|
||||
// Next, we'll extract the number of minutes that are remaining for a cache
|
||||
// so that we can properly retain the time for things like the increment
|
||||
// operation that may be performed on the cache. We'll round this out.
|
||||
$time = ceil(($expire - time()) / 60);
|
||||
|
||||
return compact('data', 'time');
|
||||
}
|
||||
return compact('data', 'time');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$value = $this->expiration($minutes).serialize($value);
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$value = $this->expiration($minutes).serialize($value);
|
||||
|
||||
$this->createCacheDirectory($path = $this->path($key));
|
||||
$this->createCacheDirectory($path = $this->path($key));
|
||||
|
||||
$this->files->put($path, $value);
|
||||
}
|
||||
$this->files->put($path, $value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the file cache directory if necessary.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
protected function createCacheDirectory($path)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->files->makeDirectory(dirname($path), 0777, true, true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create the file cache directory if necessary.
|
||||
*
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
protected function createCacheDirectory($path)
|
||||
{
|
||||
if (! $this->files->exists(dirname($path))) {
|
||||
$this->files->makeDirectory(dirname($path), 0777, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
$raw = $this->getPayload($key);
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
$raw = $this->getPayload($key);
|
||||
|
||||
$int = ((int) $raw['data']) + $value;
|
||||
$int = ((int) $raw['data']) + $value;
|
||||
|
||||
$this->put($key, $int, (int) $raw['time']);
|
||||
$this->put($key, $int, (int) $raw['time']);
|
||||
|
||||
return $int;
|
||||
}
|
||||
return $int;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->increment($key, $value * -1);
|
||||
}
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->increment($key, $value * -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 0);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$file = $this->path($key);
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$file = $this->path($key);
|
||||
|
||||
if ($this->files->exists($file))
|
||||
{
|
||||
return $this->files->delete($file);
|
||||
}
|
||||
if ($this->files->exists($file)) {
|
||||
return $this->files->delete($file);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
if ($this->files->isDirectory($this->directory))
|
||||
{
|
||||
foreach ($this->files->directories($this->directory) as $directory)
|
||||
{
|
||||
$this->files->deleteDirectory($directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
if ($this->files->isDirectory($this->directory)) {
|
||||
foreach ($this->files->directories($this->directory) as $directory) {
|
||||
$this->files->deleteDirectory($directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path for the given cache key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function path($key)
|
||||
{
|
||||
$parts = array_slice(str_split($hash = md5($key), 2), 0, 2);
|
||||
/**
|
||||
* Get the full path for the given cache key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function path($key)
|
||||
{
|
||||
$parts = array_slice(str_split($hash = sha1($key), 2), 0, 2);
|
||||
|
||||
return $this->directory.'/'.implode('/', $parts).'/'.$hash;
|
||||
}
|
||||
return $this->directory.'/'.implode('/', $parts).'/'.$hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expiration time based on the given minutes.
|
||||
*
|
||||
* @param int $minutes
|
||||
* @return int
|
||||
*/
|
||||
protected function expiration($minutes)
|
||||
{
|
||||
if ($minutes === 0) return 9999999999;
|
||||
/**
|
||||
* Get the expiration time based on the given minutes.
|
||||
*
|
||||
* @param int $minutes
|
||||
* @return int
|
||||
*/
|
||||
protected function expiration($minutes)
|
||||
{
|
||||
$time = time() + ($minutes * 60);
|
||||
|
||||
return time() + ($minutes * 60);
|
||||
}
|
||||
if ($minutes === 0 || $time > 9999999999) {
|
||||
return 9999999999;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Filesystem instance.
|
||||
*
|
||||
* @return \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
public function getFilesystem()
|
||||
{
|
||||
return $this->files;
|
||||
}
|
||||
return (int) $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the working directory of the cache.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDirectory()
|
||||
{
|
||||
return $this->directory;
|
||||
}
|
||||
/**
|
||||
* Get the Filesystem instance.
|
||||
*
|
||||
* @return \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
public function getFilesystem()
|
||||
{
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* Get the working directory of the cache.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDirectory()
|
||||
{
|
||||
return $this->directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,53 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Memcached;
|
||||
use RuntimeException;
|
||||
|
||||
class MemcachedConnector {
|
||||
class MemcachedConnector
|
||||
{
|
||||
/**
|
||||
* Create a new Memcached connection.
|
||||
*
|
||||
* @param array $servers
|
||||
* @return \Memcached
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function connect(array $servers)
|
||||
{
|
||||
$memcached = $this->getMemcached();
|
||||
|
||||
/**
|
||||
* Create a new Memcached connection.
|
||||
*
|
||||
* @param array $servers
|
||||
* @return \Memcached
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function connect(array $servers)
|
||||
{
|
||||
$memcached = $this->getMemcached();
|
||||
// For each server in the array, we'll just extract the configuration and add
|
||||
// the server to the Memcached connection. Once we have added all of these
|
||||
// servers we'll verify the connection is successful and return it back.
|
||||
foreach ($servers as $server) {
|
||||
$memcached->addServer(
|
||||
$server['host'], $server['port'], $server['weight']
|
||||
);
|
||||
}
|
||||
|
||||
// For each server in the array, we'll just extract the configuration and add
|
||||
// the server to the Memcached connection. Once we have added all of these
|
||||
// servers we'll verify the connection is successful and return it back.
|
||||
foreach ($servers as $server)
|
||||
{
|
||||
$memcached->addServer(
|
||||
$server['host'], $server['port'], $server['weight']
|
||||
);
|
||||
}
|
||||
$memcachedStatus = $memcached->getVersion();
|
||||
|
||||
$memcachedStatus = $memcached->getVersion();
|
||||
if (! is_array($memcachedStatus)) {
|
||||
throw new RuntimeException('No Memcached servers added.');
|
||||
}
|
||||
|
||||
if ( ! is_array($memcachedStatus))
|
||||
{
|
||||
throw new RuntimeException("No Memcached servers added.");
|
||||
}
|
||||
if (in_array('255.255.255', $memcachedStatus) && count(array_unique($memcachedStatus)) === 1) {
|
||||
throw new RuntimeException('Could not establish Memcached connection.');
|
||||
}
|
||||
|
||||
if (in_array('255.255.255', $memcachedStatus) && count(array_unique($memcachedStatus)) === 1)
|
||||
{
|
||||
throw new RuntimeException("Could not establish Memcached connection.");
|
||||
}
|
||||
|
||||
return $memcached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new Memcached instance.
|
||||
*
|
||||
* @return \Memcached
|
||||
*/
|
||||
protected function getMemcached()
|
||||
{
|
||||
return new Memcached;
|
||||
}
|
||||
return $memcached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new Memcached instance.
|
||||
*
|
||||
* @return \Memcached
|
||||
*/
|
||||
protected function getMemcached()
|
||||
{
|
||||
return new Memcached;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,153 +1,206 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Memcached;
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class MemcachedStore extends TaggableStore implements Store {
|
||||
class MemcachedStore extends TaggableStore implements Store
|
||||
{
|
||||
/**
|
||||
* The Memcached instance.
|
||||
*
|
||||
* @var \Memcached
|
||||
*/
|
||||
protected $memcached;
|
||||
|
||||
/**
|
||||
* The Memcached instance.
|
||||
*
|
||||
* @var \Memcached
|
||||
*/
|
||||
protected $memcached;
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
/**
|
||||
* Create a new Memcached store.
|
||||
*
|
||||
* @param \Memcached $memcached
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($memcached, $prefix = '')
|
||||
{
|
||||
$this->setPrefix($prefix);
|
||||
$this->memcached = $memcached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Memcached store.
|
||||
*
|
||||
* @param \Memcached $memcached
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($memcached, $prefix = '')
|
||||
{
|
||||
$this->memcached = $memcached;
|
||||
$this->prefix = strlen($prefix) > 0 ? $prefix.':' : '';
|
||||
}
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = $this->memcached->get($this->prefix.$key);
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = $this->memcached->get($this->prefix.$key);
|
||||
if ($this->memcached->getResultCode() == 0) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->memcached->getResultCode() == 0)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieve multiple items from the cache by key.
|
||||
*
|
||||
* Items not found in the cache will have a null value.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
public function many(array $keys)
|
||||
{
|
||||
$prefixedKeys = array_map(function ($key) {
|
||||
return $this->prefix.$key;
|
||||
}, $keys);
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->memcached->set($this->prefix.$key, $value, $minutes * 60);
|
||||
}
|
||||
$values = $this->memcached->getMulti($prefixedKeys, null, Memcached::GET_PRESERVE_ORDER);
|
||||
|
||||
/**
|
||||
* Store an item in the cache if the key doesn't exist.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return bool
|
||||
*/
|
||||
public function add($key, $value, $minutes)
|
||||
{
|
||||
return $this->memcached->add($this->prefix.$key, $value, $minutes * 60);
|
||||
}
|
||||
if ($this->memcached->getResultCode() != 0) {
|
||||
return array_fill_keys($keys, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return $this->memcached->increment($this->prefix.$key, $value);
|
||||
}
|
||||
return array_combine($keys, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->memcached->decrement($this->prefix.$key, $value);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$this->memcached->set($this->prefix.$key, $value, $minutes * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 0);
|
||||
}
|
||||
/**
|
||||
* Store multiple items in the cache for a given number of minutes.
|
||||
*
|
||||
* @param array $values
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function putMany(array $values, $minutes)
|
||||
{
|
||||
$prefixedValues = [];
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return $this->memcached->delete($this->prefix.$key);
|
||||
}
|
||||
foreach ($values as $key => $value) {
|
||||
$prefixedValues[$this->prefix.$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->memcached->flush();
|
||||
}
|
||||
$this->memcached->setMulti($prefixedValues, $minutes * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Memcached connection.
|
||||
*
|
||||
* @return \Memcached
|
||||
*/
|
||||
public function getMemcached()
|
||||
{
|
||||
return $this->memcached;
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache if the key doesn't exist.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return bool
|
||||
*/
|
||||
public function add($key, $value, $minutes)
|
||||
{
|
||||
return $this->memcached->add($this->prefix.$key, $value, $minutes * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return $this->memcached->increment($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->memcached->decrement($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return $this->memcached->delete($this->prefix.$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->memcached->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying Memcached connection.
|
||||
*
|
||||
* @return \Memcached
|
||||
*/
|
||||
public function getMemcached()
|
||||
{
|
||||
return $this->memcached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache key prefix.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefix = ! empty($prefix) ? $prefix.':' : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,105 +1,108 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class NullStore extends TaggableStore implements Store {
|
||||
class NullStore extends TaggableStore implements Store
|
||||
{
|
||||
use RetrievesMultipleKeys;
|
||||
|
||||
/**
|
||||
* The array of stored values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $storage = array();
|
||||
/**
|
||||
* The array of stored values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $storage = [];
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
125
vendor/laravel/framework/src/Illuminate/Cache/RateLimiter.php
vendored
Normal file
125
vendor/laravel/framework/src/Illuminate/Cache/RateLimiter.php
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Contracts\Cache\Repository as Cache;
|
||||
|
||||
class RateLimiter
|
||||
{
|
||||
/**
|
||||
* The cache store implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Create a new rate limiter instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Repository $cache
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Cache $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given key has been "accessed" too many times.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $maxAttempts
|
||||
* @param int $decayMinutes
|
||||
* @return bool
|
||||
*/
|
||||
public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1)
|
||||
{
|
||||
if ($this->cache->has($key.':lockout')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->attempts($key) > $maxAttempts) {
|
||||
$this->cache->add($key.':lockout', time() + ($decayMinutes * 60), $decayMinutes);
|
||||
|
||||
$this->resetAttempts($key);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the counter for a given key for a given decay time.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $decayMinutes
|
||||
* @return int
|
||||
*/
|
||||
public function hit($key, $decayMinutes = 1)
|
||||
{
|
||||
$this->cache->add($key, 1, $decayMinutes);
|
||||
|
||||
return (int) $this->cache->increment($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of attempts for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function attempts($key)
|
||||
{
|
||||
return $this->cache->get($key, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the number of attempts for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function resetAttempts($key)
|
||||
{
|
||||
return $this->cache->forget($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of retries left for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $maxAttempts
|
||||
* @return int
|
||||
*/
|
||||
public function retriesLeft($key, $maxAttempts)
|
||||
{
|
||||
$attempts = $this->attempts($key);
|
||||
|
||||
return $attempts === 0 ? $maxAttempts : $maxAttempts - $attempts + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the hits and lockout for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function clear($key)
|
||||
{
|
||||
$this->resetAttempts($key);
|
||||
|
||||
$this->cache->forget($key.':lockout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of seconds until the "key" is accessible again.
|
||||
*
|
||||
* @param string $key
|
||||
* @return int
|
||||
*/
|
||||
public function availableIn($key)
|
||||
{
|
||||
return $this->cache->get($key.':lockout') - time();
|
||||
}
|
||||
}
|
||||
@@ -1,186 +1,238 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
use Illuminate\Redis\Database as Redis;
|
||||
|
||||
class RedisStore extends TaggableStore implements Store {
|
||||
class RedisStore extends TaggableStore implements Store
|
||||
{
|
||||
/**
|
||||
* The Redis database connection.
|
||||
*
|
||||
* @var \Illuminate\Redis\Database
|
||||
*/
|
||||
protected $redis;
|
||||
|
||||
/**
|
||||
* The Redis database connection.
|
||||
*
|
||||
* @var \Illuminate\Redis\Database
|
||||
*/
|
||||
protected $redis;
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
/**
|
||||
* The Redis connection that should be used.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The Redis connection that should be used.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection;
|
||||
/**
|
||||
* Create a new Redis store.
|
||||
*
|
||||
* @param \Illuminate\Redis\Database $redis
|
||||
* @param string $prefix
|
||||
* @param string $connection
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Redis $redis, $prefix = '', $connection = 'default')
|
||||
{
|
||||
$this->redis = $redis;
|
||||
$this->setPrefix($prefix);
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Redis store.
|
||||
*
|
||||
* @param \Illuminate\Redis\Database $redis
|
||||
* @param string $prefix
|
||||
* @param string $connection
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Redis $redis, $prefix = '', $connection = 'default')
|
||||
{
|
||||
$this->redis = $redis;
|
||||
$this->connection = $connection;
|
||||
$this->prefix = strlen($prefix) > 0 ? $prefix.':' : '';
|
||||
}
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if (! is_null($value = $this->connection()->get($this->prefix.$key))) {
|
||||
return is_numeric($value) ? $value : unserialize($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
if ( ! is_null($value = $this->connection()->get($this->prefix.$key)))
|
||||
{
|
||||
return is_numeric($value) ? $value : unserialize($value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieve multiple items from the cache by key.
|
||||
*
|
||||
* Items not found in the cache will have a null value.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
public function many(array $keys)
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$value = is_numeric($value) ? $value : serialize($value);
|
||||
$prefixedKeys = array_map(function ($key) {
|
||||
return $this->prefix.$key;
|
||||
}, $keys);
|
||||
|
||||
$minutes = max(1, $minutes);
|
||||
$values = $this->connection()->mget($prefixedKeys);
|
||||
|
||||
$this->connection()->setex($this->prefix.$key, $minutes * 60, $value);
|
||||
}
|
||||
foreach ($values as $index => $value) {
|
||||
$return[$keys[$index]] = is_numeric($value) ? $value : unserialize($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return $this->connection()->incrby($this->prefix.$key, $value);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->connection()->decrby($this->prefix.$key, $value);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$value = is_numeric($value) ? $value : serialize($value);
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$value = is_numeric($value) ? $value : serialize($value);
|
||||
$this->connection()->setex($this->prefix.$key, (int) max(1, $minutes * 60), $value);
|
||||
}
|
||||
|
||||
$this->connection()->set($this->prefix.$key, $value);
|
||||
}
|
||||
/**
|
||||
* Store multiple items in the cache for a given number of minutes.
|
||||
*
|
||||
* @param array $values
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function putMany(array $values, $minutes)
|
||||
{
|
||||
$this->connection()->multi();
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return (bool) $this->connection()->del($this->prefix.$key);
|
||||
}
|
||||
foreach ($values as $key => $value) {
|
||||
$this->put($key, $value, $minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->connection()->flushdb();
|
||||
}
|
||||
$this->connection()->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin executing a new tags operation.
|
||||
*
|
||||
* @param array|mixed $names
|
||||
* @return \Illuminate\Cache\RedisTaggedCache
|
||||
*/
|
||||
public function tags($names)
|
||||
{
|
||||
return new RedisTaggedCache($this, new TagSet($this, is_array($names) ? $names : func_get_args()));
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return $this->connection()->incrby($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Redis connection instance.
|
||||
*
|
||||
* @return \Predis\ClientInterface
|
||||
*/
|
||||
public function connection()
|
||||
{
|
||||
return $this->redis->connection($this->connection);
|
||||
}
|
||||
/**
|
||||
* Decrement the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return $this->connection()->decrby($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the connection name to be used.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return void
|
||||
*/
|
||||
public function setConnection($connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$value = is_numeric($value) ? $value : serialize($value);
|
||||
|
||||
/**
|
||||
* Get the Redis database instance.
|
||||
*
|
||||
* @return \Illuminate\Redis\Database
|
||||
*/
|
||||
public function getRedis()
|
||||
{
|
||||
return $this->redis;
|
||||
}
|
||||
$this->connection()->set($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return (bool) $this->connection()->del($this->prefix.$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->connection()->flushdb();
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin executing a new tags operation.
|
||||
*
|
||||
* @param array|mixed $names
|
||||
* @return \Illuminate\Cache\RedisTaggedCache
|
||||
*/
|
||||
public function tags($names)
|
||||
{
|
||||
return new RedisTaggedCache($this, new TagSet($this, is_array($names) ? $names : func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Redis connection instance.
|
||||
*
|
||||
* @return \Predis\ClientInterface
|
||||
*/
|
||||
public function connection()
|
||||
{
|
||||
return $this->redis->connection($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the connection name to be used.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return void
|
||||
*/
|
||||
public function setConnection($connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Redis database instance.
|
||||
*
|
||||
* @return \Illuminate\Redis\Database
|
||||
*/
|
||||
public function getRedis()
|
||||
{
|
||||
return $this->redis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache key prefix.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefix = ! empty($prefix) ? $prefix.':' : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +1,164 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
class RedisTaggedCache extends TaggedCache {
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->pushForeverKeys($namespace = $this->tags->getNamespace(), $key);
|
||||
class RedisTaggedCache extends TaggedCache
|
||||
{
|
||||
/**
|
||||
* Forever reference key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const REFERENCE_KEY_FOREVER = 'forever_ref';
|
||||
/**
|
||||
* Standard reference key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const REFERENCE_KEY_STANDARD = 'standard_ref';
|
||||
|
||||
$this->store->forever(sha1($namespace).':'.$key, $value);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param \DateTime|int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes = null)
|
||||
{
|
||||
$this->pushStandardKeys($this->tags->getNamespace(), $key);
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->deleteForeverKeys();
|
||||
parent::put($key, $value, $minutes);
|
||||
}
|
||||
|
||||
parent::flush();
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->pushForeverKeys($this->tags->getNamespace(), $key);
|
||||
|
||||
/**
|
||||
* Store a copy of the full key for each namespace segment.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
protected function pushForeverKeys($namespace, $key)
|
||||
{
|
||||
$fullKey = $this->getPrefix().sha1($namespace).':'.$key;
|
||||
parent::forever($key, $value);
|
||||
}
|
||||
|
||||
foreach (explode('|', $namespace) as $segment)
|
||||
{
|
||||
$this->store->connection()->lpush($this->foreverKey($segment), $fullKey);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->deleteForeverKeys();
|
||||
$this->deleteStandardKeys();
|
||||
|
||||
/**
|
||||
* Delete all of the items that were stored forever.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteForeverKeys()
|
||||
{
|
||||
foreach (explode('|', $this->tags->getNamespace()) as $segment)
|
||||
{
|
||||
$this->deleteForeverValues($segment = $this->foreverKey($segment));
|
||||
parent::flush();
|
||||
}
|
||||
|
||||
$this->store->connection()->del($segment);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Store standard key references into store.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
protected function pushStandardKeys($namespace, $key)
|
||||
{
|
||||
$this->pushKeys($namespace, $key, self::REFERENCE_KEY_STANDARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all of the keys that have been stored forever.
|
||||
*
|
||||
* @param string $foreverKey
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteForeverValues($foreverKey)
|
||||
{
|
||||
$forever = array_unique($this->store->connection()->lrange($foreverKey, 0, -1));
|
||||
/**
|
||||
* Store forever key references into store.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
protected function pushForeverKeys($namespace, $key)
|
||||
{
|
||||
$this->pushKeys($namespace, $key, self::REFERENCE_KEY_FOREVER);
|
||||
}
|
||||
|
||||
if (count($forever) > 0)
|
||||
{
|
||||
call_user_func_array(array($this->store->connection(), 'del'), $forever);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Store a reference to the cache key against the reference key.
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string $key
|
||||
* @param string $reference
|
||||
* @return void
|
||||
*/
|
||||
protected function pushKeys($namespace, $key, $reference)
|
||||
{
|
||||
$fullKey = $this->getPrefix().sha1($namespace).':'.$key;
|
||||
|
||||
/**
|
||||
* Get the forever reference key for the segment.
|
||||
*
|
||||
* @param string $segment
|
||||
* @return string
|
||||
*/
|
||||
protected function foreverKey($segment)
|
||||
{
|
||||
return $this->getPrefix().$segment.':forever';
|
||||
}
|
||||
foreach (explode('|', $namespace) as $segment) {
|
||||
$this->store->connection()->sadd($this->referenceKey($segment, $reference), $fullKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all of the items that were stored forever.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteForeverKeys()
|
||||
{
|
||||
$this->deleteKeysByReference(self::REFERENCE_KEY_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all standard items.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteStandardKeys()
|
||||
{
|
||||
$this->deleteKeysByReference(self::REFERENCE_KEY_STANDARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and delete all of the items that were stored against a reference.
|
||||
*
|
||||
* @param string $reference
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteKeysByReference($reference)
|
||||
{
|
||||
foreach (explode('|', $this->tags->getNamespace()) as $segment) {
|
||||
$this->deleteValues($segment = $this->referenceKey($segment, $reference));
|
||||
|
||||
$this->store->connection()->del($segment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item keys that have been stored against a reference.
|
||||
*
|
||||
* @param string $referenceKey
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteValues($referenceKey)
|
||||
{
|
||||
$values = array_unique($this->store->connection()->smembers($referenceKey));
|
||||
|
||||
if (count($values) > 0) {
|
||||
call_user_func_array([$this->store->connection(), 'del'], $values);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reference key for the segment.
|
||||
*
|
||||
* @param string $segment
|
||||
* @param string $suffix
|
||||
* @return string
|
||||
*/
|
||||
protected function referenceKey($segment, $suffix)
|
||||
{
|
||||
return $this->getPrefix().$segment.':'.$suffix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,369 +1,499 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use ArrayAccess;
|
||||
use Carbon\Carbon;
|
||||
use BadMethodCallException;
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Cache\Repository as CacheContract;
|
||||
|
||||
class Repository implements CacheContract, ArrayAccess {
|
||||
class Repository implements CacheContract, ArrayAccess
|
||||
{
|
||||
use Macroable {
|
||||
__call as macroCall;
|
||||
}
|
||||
|
||||
use Macroable {
|
||||
__call as macroCall;
|
||||
}
|
||||
/**
|
||||
* The cache store implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Store
|
||||
*/
|
||||
protected $store;
|
||||
|
||||
/**
|
||||
* The cache store implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Store
|
||||
*/
|
||||
protected $store;
|
||||
/**
|
||||
* The event dispatcher implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Events\Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* The event dispatcher implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Events\Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
/**
|
||||
* The default number of minutes to store items.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $default = 60;
|
||||
|
||||
/**
|
||||
* The default number of minutes to store items.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $default = 60;
|
||||
/**
|
||||
* Create a new cache repository instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Store $store
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Store $store)
|
||||
{
|
||||
$this->store = $store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new cache repository instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Store $store
|
||||
*/
|
||||
public function __construct(Store $store)
|
||||
{
|
||||
$this->store = $store;
|
||||
}
|
||||
/**
|
||||
* Set the event dispatcher instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||
* @return void
|
||||
*/
|
||||
public function setEventDispatcher(Dispatcher $events)
|
||||
{
|
||||
$this->events = $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event dispatcher instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher
|
||||
* @return void
|
||||
*/
|
||||
public function setEventDispatcher(Dispatcher $events)
|
||||
{
|
||||
$this->events = $events;
|
||||
}
|
||||
/**
|
||||
* Fire an event for this cache instance.
|
||||
*
|
||||
* @param string $event
|
||||
* @param array $payload
|
||||
* @return void
|
||||
*/
|
||||
protected function fireCacheEvent($event, $payload)
|
||||
{
|
||||
if (! isset($this->events)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire an event for this cache instance.
|
||||
*
|
||||
* @param string $event
|
||||
* @param array $payload
|
||||
* @return void
|
||||
*/
|
||||
protected function fireCacheEvent($event, $payload)
|
||||
{
|
||||
if (isset($this->events))
|
||||
{
|
||||
$this->events->fire('cache.'.$event, $payload);
|
||||
}
|
||||
}
|
||||
switch ($event) {
|
||||
case 'hit':
|
||||
if (count($payload) == 2) {
|
||||
$payload[] = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an item exists in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return ! is_null($this->get($key));
|
||||
}
|
||||
return $this->events->fire(new Events\CacheHit($payload[0], $payload[1], $payload[2]));
|
||||
case 'missed':
|
||||
if (count($payload) == 1) {
|
||||
$payload[] = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
$value = $this->store->get($key);
|
||||
return $this->events->fire(new Events\CacheMissed($payload[0], $payload[1]));
|
||||
case 'delete':
|
||||
if (count($payload) == 1) {
|
||||
$payload[] = [];
|
||||
}
|
||||
|
||||
if (is_null($value))
|
||||
{
|
||||
$this->fireCacheEvent('missed', [$key]);
|
||||
return $this->events->fire(new Events\KeyForgotten($payload[0], $payload[1]));
|
||||
case 'write':
|
||||
if (count($payload) == 3) {
|
||||
$payload[] = [];
|
||||
}
|
||||
|
||||
$value = value($default);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->fireCacheEvent('hit', [$key, $value]);
|
||||
}
|
||||
return $this->events->fire(new Events\KeyWritten($payload[0], $payload[1], $payload[2], $payload[3]));
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* 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 and delete it.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function pull($key, $default = null)
|
||||
{
|
||||
$value = $this->get($key, $default);
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
return $this->many($key);
|
||||
}
|
||||
|
||||
$this->forget($key);
|
||||
$value = $this->store->get($this->itemKey($key));
|
||||
|
||||
return $value;
|
||||
}
|
||||
if (is_null($value)) {
|
||||
$this->fireCacheEvent('missed', [$key]);
|
||||
|
||||
/**
|
||||
* Store an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param \DateTime|int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$minutes = $this->getMinutes($minutes);
|
||||
$value = value($default);
|
||||
} else {
|
||||
$this->fireCacheEvent('hit', [$key, $value]);
|
||||
}
|
||||
|
||||
if ( ! is_null($minutes))
|
||||
{
|
||||
$this->store->put($key, $value, $minutes);
|
||||
return $value;
|
||||
}
|
||||
|
||||
$this->fireCacheEvent('write', [$key, $value, $minutes]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieve multiple items from the cache by key.
|
||||
*
|
||||
* Items not found in the cache will have a null value.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
public function many(array $keys)
|
||||
{
|
||||
$normalizedKeys = [];
|
||||
|
||||
/**
|
||||
* Store an item in the cache if the key does not exist.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param \DateTime|int $minutes
|
||||
* @return bool
|
||||
*/
|
||||
public function add($key, $value, $minutes)
|
||||
{
|
||||
if (method_exists($this->store, 'add'))
|
||||
{
|
||||
return $this->store->add($key, $value, $minutes);
|
||||
}
|
||||
foreach ($keys as $key => $value) {
|
||||
$normalizedKeys[] = is_string($key) ? $key : $value;
|
||||
}
|
||||
|
||||
if (is_null($this->get($key)))
|
||||
{
|
||||
$this->put($key, $value, $minutes);
|
||||
$values = $this->store->many($normalizedKeys);
|
||||
|
||||
return true;
|
||||
}
|
||||
foreach ($values as $key => &$value) {
|
||||
if (is_null($value)) {
|
||||
$this->fireCacheEvent('missed', [$key]);
|
||||
|
||||
return false;
|
||||
}
|
||||
$value = isset($keys[$key]) ? value($keys[$key]) : null;
|
||||
} else {
|
||||
$this->fireCacheEvent('hit', [$key, $value]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->store->forever($key, $value);
|
||||
return $values;
|
||||
}
|
||||
|
||||
$this->fireCacheEvent('write', [$key, $value, 0]);
|
||||
}
|
||||
/**
|
||||
* Retrieve an item from the cache and delete it.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function pull($key, $default = null)
|
||||
{
|
||||
$value = $this->get($key, $default);
|
||||
|
||||
/**
|
||||
* Get an item from the cache, or store the default value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \DateTime|int $minutes
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function remember($key, $minutes, Closure $callback)
|
||||
{
|
||||
// If the item exists in the cache we will just return this immediately
|
||||
// otherwise we will execute the given Closure and cache the result
|
||||
// of that execution for the given number of minutes in storage.
|
||||
if ( ! is_null($value = $this->get($key)))
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
$this->forget($key);
|
||||
|
||||
$this->put($key, $value = $callback(), $minutes);
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param \DateTime|int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes = null)
|
||||
{
|
||||
if (is_array($key) && filter_var($value, FILTER_VALIDATE_INT) !== false) {
|
||||
return $this->putMany($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from the cache, or store the default value forever.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function sear($key, Closure $callback)
|
||||
{
|
||||
return $this->rememberForever($key, $callback);
|
||||
}
|
||||
$minutes = $this->getMinutes($minutes);
|
||||
|
||||
/**
|
||||
* Get an item from the cache, or store the default value forever.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function rememberForever($key, Closure $callback)
|
||||
{
|
||||
// If the item exists in the cache we will just return this immediately
|
||||
// otherwise we will execute the given Closure and cache the result
|
||||
// of that execution for the given number of minutes. It's easy.
|
||||
if ( ! is_null($value = $this->get($key)))
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
if (! is_null($minutes)) {
|
||||
$this->store->put($this->itemKey($key), $value, $minutes);
|
||||
|
||||
$this->forever($key, $value = $callback());
|
||||
$this->fireCacheEvent('write', [$key, $value, $minutes]);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* Store multiple items in the cache for a given number of minutes.
|
||||
*
|
||||
* @param array $values
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function putMany(array $values, $minutes)
|
||||
{
|
||||
$minutes = $this->getMinutes($minutes);
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$success = $this->store->forget($key);
|
||||
if (! is_null($minutes)) {
|
||||
$this->store->putMany($values, $minutes);
|
||||
|
||||
$this->fireCacheEvent('delete', [$key]);
|
||||
foreach ($values as $key => $value) {
|
||||
$this->fireCacheEvent('write', [$key, $value, $minutes]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache if the key does not exist.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param \DateTime|int $minutes
|
||||
* @return bool
|
||||
*/
|
||||
public function add($key, $value, $minutes)
|
||||
{
|
||||
$minutes = $this->getMinutes($minutes);
|
||||
|
||||
/**
|
||||
* Get the default cache time.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDefaultCacheTime()
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
if (is_null($minutes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default cache time in minutes.
|
||||
*
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultCacheTime($minutes)
|
||||
{
|
||||
$this->default = $minutes;
|
||||
}
|
||||
if (method_exists($this->store, 'add')) {
|
||||
return $this->store->add($this->itemKey($key), $value, $minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache store implementation.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Cache\Store
|
||||
*/
|
||||
public function getStore()
|
||||
{
|
||||
return $this->store;
|
||||
}
|
||||
if (is_null($this->get($key))) {
|
||||
$this->put($key, $value, $minutes);
|
||||
|
||||
/**
|
||||
* Determine if a cached value exists.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($key)
|
||||
{
|
||||
return $this->has($key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($key)
|
||||
{
|
||||
return $this->get($key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for the default time.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($key, $value)
|
||||
{
|
||||
$this->put($key, $value, $this->default);
|
||||
}
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->store->forever($this->itemKey($key), $value);
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($key)
|
||||
{
|
||||
$this->forget($key);
|
||||
}
|
||||
$this->fireCacheEvent('write', [$key, $value, 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the number of minutes with the given duration.
|
||||
*
|
||||
* @param \DateTime|int $duration
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getMinutes($duration)
|
||||
{
|
||||
if ($duration instanceof DateTime)
|
||||
{
|
||||
$fromNow = Carbon::instance($duration)->diffInMinutes();
|
||||
/**
|
||||
* Get an item from the cache, or store the default value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \DateTime|int $minutes
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function remember($key, $minutes, Closure $callback)
|
||||
{
|
||||
// If the item exists in the cache we will just return this immediately
|
||||
// otherwise we will execute the given Closure and cache the result
|
||||
// of that execution for the given number of minutes in storage.
|
||||
if (! is_null($value = $this->get($key))) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $fromNow > 0 ? $fromNow : null;
|
||||
}
|
||||
$this->put($key, $value = $callback(), $minutes);
|
||||
|
||||
return is_string($duration) ? (int) $duration : $duration;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dynamic calls into macros or pass missing methods to the store.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (static::hasMacro($method))
|
||||
{
|
||||
return $this->macroCall($method, $parameters);
|
||||
}
|
||||
/**
|
||||
* Get an item from the cache, or store the default value forever.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function sear($key, Closure $callback)
|
||||
{
|
||||
return $this->rememberForever($key, $callback);
|
||||
}
|
||||
|
||||
return call_user_func_array(array($this->store, $method), $parameters);
|
||||
}
|
||||
/**
|
||||
* Get an item from the cache, or store the default value forever.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function rememberForever($key, Closure $callback)
|
||||
{
|
||||
// If the item exists in the cache we will just return this immediately
|
||||
// otherwise we will execute the given Closure and cache the result
|
||||
// of that execution for the given number of minutes. It's easy.
|
||||
if (! is_null($value = $this->get($key))) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$this->forever($key, $value = $callback());
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
$success = $this->store->forget($this->itemKey($key));
|
||||
|
||||
$this->fireCacheEvent('delete', [$key]);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin executing a new tags operation if the store supports it.
|
||||
*
|
||||
* @param array|mixed $names
|
||||
* @return \Illuminate\Cache\TaggedCache
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function tags($names)
|
||||
{
|
||||
if (method_exists($this->store, 'tags')) {
|
||||
$taggedCache = $this->store->tags($names);
|
||||
|
||||
if (! is_null($this->events)) {
|
||||
$taggedCache->setEventDispatcher($this->events);
|
||||
}
|
||||
|
||||
$taggedCache->setDefaultCacheTime($this->default);
|
||||
|
||||
return $taggedCache;
|
||||
}
|
||||
|
||||
throw new BadMethodCallException('This cache store does not support tagging.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the key for a cache item.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function itemKey($key)
|
||||
{
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default cache time.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDefaultCacheTime()
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default cache time in minutes.
|
||||
*
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultCacheTime($minutes)
|
||||
{
|
||||
$this->default = $minutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache store implementation.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Cache\Store
|
||||
*/
|
||||
public function getStore()
|
||||
{
|
||||
return $this->store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a cached value exists.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($key)
|
||||
{
|
||||
return $this->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($key)
|
||||
{
|
||||
return $this->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for the default time.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($key, $value)
|
||||
{
|
||||
$this->put($key, $value, $this->default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($key)
|
||||
{
|
||||
$this->forget($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the number of minutes with the given duration.
|
||||
*
|
||||
* @param \DateTime|int $duration
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getMinutes($duration)
|
||||
{
|
||||
if ($duration instanceof DateTime) {
|
||||
$fromNow = Carbon::now()->diffInMinutes(Carbon::instance($duration), false);
|
||||
|
||||
return $fromNow > 0 ? $fromNow : null;
|
||||
}
|
||||
|
||||
return is_string($duration) ? (int) $duration : $duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dynamic calls into macros or pass missing methods to the store.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (static::hasMacro($method)) {
|
||||
return $this->macroCall($method, $parameters);
|
||||
}
|
||||
|
||||
return call_user_func_array([$this->store, $method], $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone cache repository instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->store = clone $this->store;
|
||||
}
|
||||
}
|
||||
|
||||
39
vendor/laravel/framework/src/Illuminate/Cache/RetrievesMultipleKeys.php
vendored
Normal file
39
vendor/laravel/framework/src/Illuminate/Cache/RetrievesMultipleKeys.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
trait RetrievesMultipleKeys
|
||||
{
|
||||
/**
|
||||
* Retrieve multiple items from the cache by key.
|
||||
*
|
||||
* Items not found in the cache will have a null value.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return array
|
||||
*/
|
||||
public function many(array $keys)
|
||||
{
|
||||
$return = [];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$return[$key] = $this->get($key);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store multiple items in the cache for a given number of minutes.
|
||||
*
|
||||
* @param array $values
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function putMany(array $values, $minutes)
|
||||
{
|
||||
foreach ($values as $key => $value) {
|
||||
$this->put($key, $value, $minutes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +1,110 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class TagSet {
|
||||
class TagSet
|
||||
{
|
||||
/**
|
||||
* The cache store implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Store
|
||||
*/
|
||||
protected $store;
|
||||
|
||||
/**
|
||||
* The cache store implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Store
|
||||
*/
|
||||
protected $store;
|
||||
/**
|
||||
* The tag names.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $names = [];
|
||||
|
||||
/**
|
||||
* The tag names.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $names = array();
|
||||
/**
|
||||
* Create a new TagSet instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Store $store
|
||||
* @param array $names
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Store $store, array $names = [])
|
||||
{
|
||||
$this->store = $store;
|
||||
$this->names = $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new TagSet instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Store $store
|
||||
* @param array $names
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Store $store, array $names = array())
|
||||
{
|
||||
$this->store = $store;
|
||||
$this->names = $names;
|
||||
}
|
||||
/**
|
||||
* Reset all tags in the set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
array_walk($this->names, [$this, 'resetTag']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all tags in the set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
array_walk($this->names, array($this, 'resetTag'));
|
||||
}
|
||||
/**
|
||||
* Get the unique tag identifier for a given tag.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function tagId($name)
|
||||
{
|
||||
return $this->store->get($this->tagKey($name)) ?: $this->resetTag($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique tag identifier for a given tag.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function tagId($name)
|
||||
{
|
||||
return $this->store->get($this->tagKey($name)) ?: $this->resetTag($name);
|
||||
}
|
||||
/**
|
||||
* Get an array of tag identifiers for all of the tags in the set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function tagIds()
|
||||
{
|
||||
return array_map([$this, 'tagId'], $this->names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of tag identifiers for all of the tags in the set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function tagIds()
|
||||
{
|
||||
return array_map(array($this, 'tagId'), $this->names);
|
||||
}
|
||||
/**
|
||||
* Get a unique namespace that changes when any of the tags are flushed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return implode('|', $this->tagIds());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a unique namespace that changes when any of the tags are flushed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return implode('|', $this->tagIds());
|
||||
}
|
||||
/**
|
||||
* Reset the tag and return the new tag identifier.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function resetTag($name)
|
||||
{
|
||||
$this->store->forever($this->tagKey($name), $id = str_replace('.', '', uniqid('', true)));
|
||||
|
||||
/**
|
||||
* Reset the tag and return the new tag identifier.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function resetTag($name)
|
||||
{
|
||||
$this->store->forever($this->tagKey($name), $id = str_replace('.', '', uniqid('', true)));
|
||||
return $id;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tag identifier key for a given tag.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function tagKey($name)
|
||||
{
|
||||
return 'tag:'.$name.':key';
|
||||
}
|
||||
/**
|
||||
* Get the tag identifier key for a given tag.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function tagKey($name)
|
||||
{
|
||||
return 'tag:'.$name.':key';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the tag names in the set.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNames()
|
||||
{
|
||||
return $this->names;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,17 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
abstract class TaggableStore {
|
||||
|
||||
/**
|
||||
* Begin executing a new tags operation.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Cache\TaggedCache
|
||||
*/
|
||||
public function section($name)
|
||||
{
|
||||
return $this->tags($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin executing a new tags operation.
|
||||
*
|
||||
* @param array|mixed $names
|
||||
* @return \Illuminate\Cache\TaggedCache
|
||||
*/
|
||||
public function tags($names)
|
||||
{
|
||||
return new TaggedCache($this, new TagSet($this, is_array($names) ? $names : func_get_args()));
|
||||
}
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
abstract class TaggableStore
|
||||
{
|
||||
/**
|
||||
* Begin executing a new tags operation.
|
||||
*
|
||||
* @param array|mixed $names
|
||||
* @return \Illuminate\Cache\TaggedCache
|
||||
*/
|
||||
public function tags($names)
|
||||
{
|
||||
return new TaggedCache($this, new TagSet($this, is_array($names) ? $names : func_get_args()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,247 +1,94 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Cache;
|
||||
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class TaggedCache implements Store {
|
||||
class TaggedCache extends Repository
|
||||
{
|
||||
use RetrievesMultipleKeys;
|
||||
|
||||
/**
|
||||
* The cache store implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Store
|
||||
*/
|
||||
protected $store;
|
||||
/**
|
||||
* The tag set instance.
|
||||
*
|
||||
* @var \Illuminate\Cache\TagSet
|
||||
*/
|
||||
protected $tags;
|
||||
|
||||
/**
|
||||
* The tag set instance.
|
||||
*
|
||||
* @var \Illuminate\Cache\TagSet
|
||||
*/
|
||||
protected $tags;
|
||||
/**
|
||||
* Create a new tagged cache instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Store $store
|
||||
* @param \Illuminate\Cache\TagSet $tags
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Store $store, TagSet $tags)
|
||||
{
|
||||
parent::__construct($store);
|
||||
|
||||
/**
|
||||
* Create a new tagged cache instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Store $store
|
||||
* @param \Illuminate\Cache\TagSet $tags
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Store $store, TagSet $tags)
|
||||
{
|
||||
$this->tags = $tags;
|
||||
$this->store = $store;
|
||||
}
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an item exists in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return ! is_null($this->get($key));
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function fireCacheEvent($event, $payload)
|
||||
{
|
||||
$payload[] = $this->tags->getNames();
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
$value = $this->store->get($this->taggedItemKey($key));
|
||||
parent::fireCacheEvent($event, $payload);
|
||||
}
|
||||
|
||||
return ! is_null($value) ? $value : value($default);
|
||||
}
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
$this->store->increment($this->itemKey($key), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param \DateTime|int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
$minutes = $this->getMinutes($minutes);
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
$this->store->decrement($this->itemKey($key), $value);
|
||||
}
|
||||
|
||||
if ( ! is_null($minutes))
|
||||
{
|
||||
$this->store->put($this->taggedItemKey($key), $value, $minutes);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->tags->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache if the key does not exist.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param \DateTime|int $minutes
|
||||
* @return bool
|
||||
*/
|
||||
public function add($key, $value, $minutes)
|
||||
{
|
||||
if (is_null($this->get($key)))
|
||||
{
|
||||
$this->put($key, $value, $minutes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
$this->store->increment($this->taggedItemKey($key), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
$this->store->decrement($this->taggedItemKey($key), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->store->forever($this->taggedItemKey($key), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return $this->store->forget($this->taggedItemKey($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
$this->tags->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from the cache, or store the default value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \DateTime|int $minutes
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function remember($key, $minutes, Closure $callback)
|
||||
{
|
||||
// If the item exists in the cache we will just return this immediately
|
||||
// otherwise we will execute the given Closure and cache the result
|
||||
// of that execution for the given number of minutes in storage.
|
||||
if ( ! is_null($value = $this->get($key))) return $value;
|
||||
|
||||
$this->put($key, $value = $callback(), $minutes);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from the cache, or store the default value forever.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function sear($key, Closure $callback)
|
||||
{
|
||||
return $this->rememberForever($key, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from the cache, or store the default value forever.
|
||||
*
|
||||
* @param string $key
|
||||
* @param \Closure $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function rememberForever($key, Closure $callback)
|
||||
{
|
||||
// If the item exists in the cache we will just return this immediately
|
||||
// otherwise we will execute the given Closure and cache the result
|
||||
// of that execution for the given number of minutes. It's easy.
|
||||
if ( ! is_null($value = $this->get($key))) return $value;
|
||||
|
||||
$this->forever($key, $value = $callback());
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a fully qualified key for a tagged item.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public function taggedItemKey($key)
|
||||
{
|
||||
return sha1($this->tags->getNamespace()).':'.$key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->store->getPrefix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the number of minutes with the given duration.
|
||||
*
|
||||
* @param \DateTime|int $duration
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getMinutes($duration)
|
||||
{
|
||||
if ($duration instanceof DateTime)
|
||||
{
|
||||
$fromNow = Carbon::instance($duration)->diffInMinutes();
|
||||
|
||||
return $fromNow > 0 ? $fromNow : null;
|
||||
}
|
||||
|
||||
return is_string($duration) ? (int) $duration : $duration;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function itemKey($key)
|
||||
{
|
||||
return $this->taggedItemKey($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a fully qualified key for a tagged item.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public function taggedItemKey($key)
|
||||
{
|
||||
return sha1($this->tags->getNamespace()).':'.$key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class WinCacheStore extends TaggableStore implements Store {
|
||||
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* Create a new WinCache store.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($prefix = '')
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = wincache_ucache_get($this->prefix.$key);
|
||||
|
||||
if ($value !== false)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
wincache_ucache_set($this->prefix.$key, $value, $minutes * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return wincache_ucache_inc($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int|bool
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return wincache_ucache_dec($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
$this->put($key, $value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return wincache_ucache_delete($this->prefix.$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
wincache_ucache_clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
<?php namespace Illuminate\Cache;
|
||||
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
|
||||
class XCacheStore extends TaggableStore implements Store {
|
||||
|
||||
/**
|
||||
* A string that should be prepended to keys.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* Create a new WinCache store.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($prefix = '')
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = xcache_get($this->prefix.$key);
|
||||
|
||||
if (isset($value))
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache for a given number of minutes.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $minutes
|
||||
* @return void
|
||||
*/
|
||||
public function put($key, $value, $minutes)
|
||||
{
|
||||
xcache_set($this->prefix.$key, $value, $minutes * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function increment($key, $value = 1)
|
||||
{
|
||||
return xcache_inc($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value of an item in the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return int
|
||||
*/
|
||||
public function decrement($key, $value = 1)
|
||||
{
|
||||
return xcache_dec($this->prefix.$key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an item in the cache indefinitely.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function forever($key, $value)
|
||||
{
|
||||
return $this->put($key, $value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function forget($key)
|
||||
{
|
||||
return xcache_unset($this->prefix.$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all items from the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
xcache_clear_cache(XC_TYPE_VAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cache key prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPrefix()
|
||||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,10 +14,10 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/contracts": "5.0.*",
|
||||
"illuminate/support": "5.0.*",
|
||||
"nesbot/carbon": "~1.0"
|
||||
"php": ">=5.5.9",
|
||||
"illuminate/contracts": "5.2.*",
|
||||
"illuminate/support": "5.2.*",
|
||||
"nesbot/carbon": "~1.20"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -26,13 +26,13 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0-dev"
|
||||
"dev-master": "5.2-dev"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"illuminate/database": "Required to use the database cache driver (5.0.*).",
|
||||
"illuminate/filesystem": "Required to use the file cache driver (5.0.*).",
|
||||
"illuminate/redis": "Required to use the redis cache driver (5.0.*)."
|
||||
"illuminate/database": "Required to use the database cache driver (5.2.*).",
|
||||
"illuminate/filesystem": "Required to use the file cache driver (5.2.*).",
|
||||
"illuminate/redis": "Required to use the redis cache driver (5.2.*)."
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user