0

I would like to know how we can control the cache lifetime on a collection.

Here's how I initialize caching on my collection:

public function _construct() 
{
    ...

    // Configure collection cache
    $this->initCache(
        Mage::app()->getCacheInstance(),
        'MY_COLLECTION',
        array(Namespace_Module_Model_Something::CACHE_TAG)
    );
    parent::_construct();
}

Where the cache instance comes from Mage_Core_Model_Cache. I can see how its frontend model is created out of Zend_Cache_Core -- whose class provides a cache lifetime setter. But this does not appear to solve my problem.

I'm using APC caching on the backend, and that's what I want to modify when the cache entry is written. And I'd like to be able to control this per collection (as in the constructor shown above).

Is this possible?

1 Answer 1

1

Well, I figured it out. Was simpler than I expected.

The clue came out of Mage::app()->saveCache(), which is simple a wrapper method for the cache model's save routine:

$this->_cache->save($data, $id, $tags, $lifeTime);

When I noticed the $lifeTime parameter, it dawned on me that the save method accepts a fourth param * facepalm * -- well, hopefully this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.