As far as I can figure this seems to be the way to set up Memcached and set the TTL and Namespace but they have no effect in the cache. The key is not prefixed with a namespace and the expire is infinite.
$MemcachedOptions = new \Zend\Cache\Storage\Adapter\MemcachedOptions();
$MemcachedResourceManager = new \Zend\Cache\Storage\Adapter\MemcachedResourceManager(1, new \Zend\Cache\Storage\Adapter\Memcached());
$MemcachedResourceManager->addServer(1, array('localhost', 11211));
$MemcachedOptions->setResourceManager($MemcachedResourceManager);
$MemcachedOptions->setNamespace('FooBar_');
$MemcachedOptions->setTtl(10);
$cache = $MemcachedOptions->getResourceManager()->getResource(1);
$cache->set('foobar_key','I am in cache');
Does anyone have any tips, clues? Any help would be much appreciated.
The
MemcachedResourceManager
works different as you trying to use it.You should initialize it like the following:
How does the classes work together:
The most important class is
Zend\Cache\Storage\Adapter\Memcached
it is a wrapper for a native instance ofMemcached
used in a context ofZend\Cache\StorageInterface
.This storage adapter has a number of options defined as
Zend\Cache\Storage\Adapter\MemcachedOptions
.Because cache storage adapters in ZF2 are designed to handle one type of items to store you need different instances of
Zend\Cache\Storage\Adapter\Memcached
for different type of items. But you don't wont to use different connections to a memcached (different instance of the nativeMemcached
class) server - this is wereZend\Cache\Storage\Adapter\MemcachedResourceManager
comes to play.The
Zend\Cache\Storage\Adapter\MemcachedResourceManager
handles native instances ofMemcached
which will be used byZend\Cache\Storage\Adapter\Memcached
.