Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony app/console cache:clear --env=prod and cache (APC, Memcached, etc)?

I'm using a Memcached server (along with memcache PHP extension) to cache validator metadata and Doctrine metatada/result/query cache driver.

Everything works as expected and is fast compared to filesystem cache.

My question is, does the command:

php app/console cache:clear --env=prod --no-debug

automatically clear all types of cache (including memcache)?

After running this command and checking the server stats, items count is always the same as well as cache occupation:

enter image description here

My configuration, where %prod_cache% parameter is actually the string memcache:

# Framework Configuration
framework:
    validation:
        cache: %prod_cache% # Matches validator cache service

# Doctrine Configuration
doctrine:
    orm:
        metadata_cache_driver:
            type: service
            id: cache_%prod_cache%
        result_cache_driver:
            type: service
            id: cache_%prod_cache%
        query_cache_driver:
            type: service
            id: cache_%prod_cache%

# DoctrineCacheBundle Configuration
doctrine_cache:
    providers:
        memcache:
            type: memcache
            alias: cache_memcache

# Services
services:
    validator.mapping.cache.memcache: # Validator cache service
        class: Symfony\Component\Validator\Mapping\Cache\DoctrineCache
        arguments: [@cache_memcache]
like image 423
gremo Avatar asked Jun 22 '14 17:06

gremo


1 Answers

cache:clear

The cache:clear command doesn't clear the Doctrine caches. It only clears some Symfony 2 framework specific caches, mainly the app/cache (or var/cache) directories.

Doctrine commands

In order to clear the Doctrine caches, use:

  • doctrine:cache:clear-metadata --env=prod
  • doctrine:cache:clear-query --env=prod
  • doctrine:cache:clear-result --env=prod

Additional caches

If you use additional cache stores, you'll have to clear them yourself. You can look at the doctrine:cache:clear-* commands to get inspired on how to create your own command.

But looking at you configuration, you use a single cache store for the 3 Doctrine caches and Symfony Validator cache. So calling just one of the doctrine:cache:clear-* should clear everything.

Off topic

When using a cache system like APC, OPcache, and maybe others, you'll have to understand that when you run a PHP script from the command line, a different memory space is used then when running a PHP script from a webserver.

In other words: when you clear such caches from the command line, the caches used by the webserver are not affected. In order to clear the webserver caches, you'll need to run the cache clear script(s) from the webserver itself.

This is not an issue for memcached, because it's a separate program managing its own memory space.

like image 146
Jasper N. Brouwer Avatar answered Oct 28 '22 22:10

Jasper N. Brouwer