Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 3.x How to clear cache for views using console?

My CakePHP 3.x app is hosted in bitbucket.

I have a deploy script that will git clone to a folder that uses timestamp as folder name.

After which the script will then create symlink /var/virtual/webapp/current to this timestamped folder.

However, for some reason, the view files are still cached despite this newly deployed folder. Also the tmp folder is empty.

How do I clear cache for view files using the console, so I can add it into the bash script?

'Cache' => [
        'default' => [
            'className' => 'File',
            'path' => CACHE,
        ],

        /**
         * Configure the cache used for general framework caching. Path information,
         * object listings, and translation cache files are stored with this
         * configuration.
         */
        '_cake_core_' => [
            'className' => 'File',
            'prefix' => 'myapp_cake_core_',
            'path' => CACHE . 'persistent/',
            'serialize' => true,
            'duration' => '+2 minutes',
        ],

        /**
         * Configure the cache for model and datasource caches. This cache
         * configuration is used to store schema descriptions, and table listings
         * in connections.
         */
        '_cake_model_' => [
            'className' => 'File',
            'prefix' => 'myapp_cake_model_',
            'path' => CACHE . 'models/',
            'serialize' => true,
            'duration' => '+2 minutes',
        ],
    ],
like image 556
Kim Stacks Avatar asked Apr 27 '15 10:04

Kim Stacks


3 Answers

Try this

// Clear one cache config
bin/cake cache clear <configname>

// Clear all cache configs
bin/cake cache clear_all
like image 165
Fury Avatar answered Oct 23 '22 23:10

Fury


You can use next command to clear all cache via console: bin/cake console Cake\Cache\Cache::clear(false)

CakePHP: Clearing Cached Data

like image 36
user9652823 Avatar answered Oct 23 '22 23:10

user9652823


So you want to clear the cache from the console?

Clearing Cache in Cakephp

Does the below not work for you?

// Will only clear expired keys.
Cache::clear(true);

// Will clear all keys.
Cache::clear(false);

You could create a shell script and could put it there.

Shells and Console

Or just delete all the files in the folder you specified for cache with rm...

rm -f /path/to/my/cached/files/*

P.S.

  • This does not cover anything cached via php opcache. Is that enabled? That could also be what is caching the view files
  • There is also the potential that your script isn't actually updating the symlink to the current directory?
like image 1
styks Avatar answered Oct 23 '22 23:10

styks