MemcachedResourceManager
当您尝试使用它时,其工作方式会有所不同。
你应该像下面这样初始化它:
// init a memcached resource manager with one native memcached resource
// using resource id "1"
$MemcachedResourceManager = new \Zend\Cache\Storage\Adapter\MemcachedResourceManager();
$MemcachedResourceManager->addServer('1', array('localhost', 11211));
// init a memcached storage adapter
// using the native memcached resource of id "1"
// configure it with a ttl and a namespace
$cache = \Zend\Cache\StorageFactory::adapterFactory('memcached', array(
'resource_manager' => $MemcachedResourceManager,
'resource_id' => '1',
'namespace' => 'FooBar_',
'ttl' => 10,
));
// or
$memcachedAdapterOptions = new \Zend\Cache\Storage\Adapter\MemcachedOptions(array(
'resource_manager' => $MemcachedResourceManager,
'resource_id' => '1',
'namespace' => 'FooBar_',
'ttl' => 10,
));
$cache = new \Zend\Cache\Storage\Adapter\Memcached($memcachedAdapterOptions);
这些类如何协同工作:
最重要的类是Zend\Cache\Storage\Adapter\Memcached
它是Memcached
在Zend\Cache\StorageInterface
.
此存储适配器有许多定义为Zend\Cache\Storage\Adapter\MemcachedOptions
.
因为 ZF2 中的缓存存储适配器旨在处理一种类型的项目来存储您需要不同Zend\Cache\Storage\Adapter\Memcached
类型的项目的不同实例。但是您不会使用与 memcached(本地Memcached
类的不同实例)服务器的不同连接 - 这是Zend\Cache\Storage\Adapter\MemcachedResourceManager
可以发挥作用的。
将使用的Zend\Cache\Storage\Adapter\MemcachedResourceManager
句柄本机实例。Memcached
Zend\Cache\Storage\Adapter\Memcached