cacher icon indicating copy to clipboard operation
cacher copied to clipboard

Clear using deleteAll and updateAll

Open elgrones opened this issue 9 years ago • 2 comments

Hi cache cleaning does not work when using the methods deleteAll() and updateAll()

elgrones avatar May 31 '15 03:05 elgrones

Yes, this is because deleteAll() and updateAll() do not trigger callbacks by default, which are what Cacher uses to determine what file it should clean. While those methods support triggering callbacks (third param), Cacher doesn't officially support them and there are no tests for them. (From what I remember it probably wouldn't work by default because the conditions [which are used to determine what cache file to remove] used in the deleteAll call likely don't match a prior find() call.

Instead, you should manually clear the cache after using those methods:

$this->Model->deleteAll(array('Model.field' => true));
$this->Model->clearCache();

Or, iterate through ids and delete them individually (slower).

jeremyharris avatar Jun 01 '15 15:06 jeremyharris

Didn't mean to close this. Do you want to work on support for these methods? I think it may require a find() beforehand to determine ids, then clearing those specific ids. Likely not the most performant solution but I can't think of another one off the top of my head.

jeremyharris avatar Jun 01 '15 15:06 jeremyharris