fstab
fstab

Reputation: 5029

How to add custom behaviour to symfony cache:clear?

I need to add a simple call to (new sfAPCCache())->clean(), or to apc_clear_cache() when the command ./symfony cc is performed.

Anyone knows how to achieve this? In which point should I edit my symfony application, or how should i register this additional behavior?

Upvotes: 2

Views: 992

Answers (2)

fstab
fstab

Reputation: 5029

Actually, I discovered that I can listen to an event to add new behavior to ./symfony cc:

$this->dispatcher->connect('task.cache.clear', array('ClearAPCCache','clearCache'))

Remains the problem that is not possibile to clear the APC cache from a command-line task because APC cache is related to the web server process, while the symfony command is a command-line script.

Upvotes: 4

j_freyre
j_freyre

Reputation: 4738

You just have to create your own custom task.

./symfony generate:task your_task_name

In this task (in the lib folder) you just have to run something like

protected function execute($arguments = array(), $options = array())
{
    // Run your own apc cache
    // ...

    /// Then run the cache:clear
    $this->runTask('cache:clear');
}

Upvotes: 2

Related Questions