Override cache clean method in custom cache - Magento 1.9

72 Views Asked by At

This is more an "Is it possible to do it" instead of "How to do it" type of question.

I have a custom module where I use the Magento 1.9 cache system to store the path of certain files. For example:

Mage::app()->getCache()->save("path/to/file.txt", "MY_CACHE_ID")

So, in my cache, I have something like:

array("MY_CACHE_ID" => "path/to/file.txt");

When I clear it using Mage::app()->getCache()->remove("MY_CACHE_ID") or refresh/clean all cache through admin panel, my cache is correctly deleted BUT my file.txt don't (as expected).

I want to know if it's possible to override my cache's method used to clean it to be able to delete (unlink) the file stored in it. Or even: delete all files inside the folder /path/to/ whenever the cache is deleted using one of the above clearing methods.

I've across an "override option" to place in my module's config.xml like so:

<config>
    <global>
         <cache>
            <types>
                <my_cache translate="label description" module="module">
                    <label>My Cache</label>
                    <tags>MY_CACHE_TAG</tags>
                    <backend_model>module/cache</backend_model>
                </my_cache>
            </types>
        </cache>
    </global>
</config>

And, in my module/cache model:

<?php

class My_Module_Model_Cache extends Zend_Cache_Backend
{
    protected function _clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
    {
        // Handle here the file deletion
    }
}

But the _clean method wasn't called.

I've also tried to find an event dispatched on cache's clearing, but didn't find any.

So, it's possible to do it?

0

There are 0 best solutions below