codlib
codlib

Reputation: 638

In Zend how to disable cache for a module?

I am working on an application with multiple number of modules with cache enabled. Cache initialization is done in application main bootstrap as follows.

$this->bootstrap('cachemanager');
$manager = $this->getPluginResource('cachemanager')->getCacheManager();
$cacheObj   = $manager->getCache('database');
Zend_Registry::set('cacheObj', $cacheObj); 

Can someone tell me, How do i disable cache for a particular module?

Upvotes: 0

Views: 4591

Answers (1)

drew010
drew010

Reputation: 69937

To disable a cache object from fetching or saving to the cache, you can set the option caching to false.

With your object, you could do:

$cacheObj = Zend_Registry::get('cacheObj');
if ($cacheObj instanceof Zend_Cache_Core) {
    $cacheObj->setOption('caching', false);
}

To make this automatic, you can write a controller plugin to do this for you. Here is an example:

<?php
class Application_Plugin_DisableCache extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $module = $request->getModuleName();

        // change 'dont_cache_me' to the module you want to disable caching in
        if ('dont_cache_me' == $module) {
            $cacheObj = Zend_Registry::get('cacheObj');
            if ($cacheObj instanceof Zend_Cache_Core) {
                $cacheObj->setOption('caching', false);
            }
        }
    }
}

Upvotes: 2

Related Questions