Search code examples
phpzend-frameworkzend-cache

Zend Cache Backend Static Remove/Clean


I'm trying to implement a cache using Zend Cache. I use the following code to initialize the caches.

$tagCache = Zend_Cache::factory('Core',
                                'File',
                                 array('automatic_serialization' => true),
                                 array('cache_dir' => $cfg['instdir']. 'Cache_dir'));

$cache = Zend_Cache::factory('Capture',
                             'Static',
                              array(),
                              array('index_filename' => 'index',
                                    'public_dir'     => $cfg['instdir'] . 'Cached',
                                    'tag_cache'      => $tagCache));

I use the following code to start caching:

$id = bin2hex($_SERVER["REQUEST_URI"]);
$cache->start($id, array());

The cache files are generated but I can't delete them using the remove() method (the cache doesn't refresh):

$cache->remove($id); // id generated like above from the REQUEST_URI of the page I want to refresh

What am I doing wrong ? Thanks.


Solution

  • $cache->remove() is a proxy to the backend's remove() method. In this case you are using the Static backend and so we look in there to find out what's happening.

    My reading of that method leads me to believe that the $id parameter to remove has to be a filename, so:

    $cache->remove('index'); 
    

    will work.

    The more usual way to clear a cache is to use the clean() method though. See the manual.