Search code examples
symfonycachingapc

symfony2 : How to disable APC cache selectively on few routes


I am using symfony version 2.3 . I have used following in my config.yml

metadata_cache_driver: apc
result_cache_driver: apc
query_cache_driver: apc

I want to disable caching at following URL . www.domain.com/dashboard

How can I achieve this ? Any help


Solution

  • In your app.php or index.php you should have something like this :

    $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
    $apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
    $loader->unregister();
    $apcLoader->register(true);
    
    require_once __DIR__.'/../app/AppKernel.php';
    require_once __DIR__.'/../app/AppCache.php';
    
    $kernel = new AppKernel('prod', false);
    $kernel->loadClassCache();
    $kernel = new AppCache($kernel);
    
    // ...
    

    so you can have a condition with $_SERVER['REQUEST_URI']

    e.g

    $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
    
    require_once __DIR__.'/../app/AppKernel.php';
    
    $kernel = new AppKernel('prod', false);
    $kernel->loadClassCache();
    
    if (!preg_match('#dashboard#'), $_SERVER['REQUEST_URI']) {
        $apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
        $loader->unregister();
        $apcLoader->register(true);
    
        require_once __DIR__.'/../app/AppCache.php';
    
        $kernel = new AppCache($kernel);
    }
    
    // ...
    

    hope it helps