2017-02-23 20:39:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Core\Cache;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
use Symfony\Component\Cache\Simple\MemcachedCache;
|
|
|
|
use Memcached;
|
|
|
|
|
|
|
|
class MemcachedCacheFactory implements CacheFactory
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Memcached
|
|
|
|
*/
|
|
|
|
protected $memcachedClient;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Memcached $memcachedClient
|
|
|
|
*/
|
2017-05-02 23:54:14 +02:00
|
|
|
public function __construct(Memcached $memcachedClient = null)
|
2017-02-23 20:39:57 +01:00
|
|
|
{
|
|
|
|
$this->memcachedClient = $memcachedClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function create($service, array $params = array())
|
|
|
|
{
|
2017-05-02 23:54:14 +02:00
|
|
|
$namespace = isset($params['namespace'])
|
|
|
|
? $params['namespace'] . '_' . md5(BASE_PATH)
|
|
|
|
: md5(BASE_PATH);
|
|
|
|
$defaultLifetime = isset($params['defaultLifetime']) ? $params['defaultLifetime'] : 0;
|
|
|
|
return Injector::inst()->createWithArgs(MemcachedCache::class, [
|
2017-02-23 20:39:57 +01:00
|
|
|
$this->memcachedClient,
|
2017-05-02 23:54:14 +02:00
|
|
|
$namespace,
|
|
|
|
$defaultLifetime
|
2017-02-23 20:39:57 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|