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
MemcachedResourceManagerworks 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\Memcachedit is a wrapper for a native instance ofMemcachedused 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\Memcachedfor different type of items. But you don't wont to use different connections to a memcached (different instance of the nativeMemcachedclass) server - this is wereZend\Cache\Storage\Adapter\MemcachedResourceManagercomes to play.The
Zend\Cache\Storage\Adapter\MemcachedResourceManagerhandles native instances ofMemcachedwhich will be used byZend\Cache\Storage\Adapter\Memcached.