Search code examples
zend-frameworkcachingzend-cache

Zend Cache Exist Function


I am using Zend Cache in my current project and its working fine .
But I want it to work more fast so I want to check if cache exists before I use load function of zend cache.
Following is my code :

$cache = Zend_Registry::get('cache');

if(!$result = $cache->load('firstfile')) {
    $newArray = 'firstfile';
    $cache->save($newArray, 'firstfile');
} else {

    echo 'retrieving cache data';
    Zend_Debug::dump($result);
}

I read documents of zend cache. It says we only use load this way to check cache exists or not. I want to know is there any other zend cache function available like hasCached or something like so we can use it to check cache exists or not before we use load function.

Thanks in Advance... :)


Solution

  • The getIds() function return array of stored cache ids.

    So I think you can try something like this:

    $id_list =  $cache->getIds();
    if (in_array('firstfile', $id_list)) {
        $result = $cache->load('firstfile');
    }
    

    I have not test it, just an idea. :)