Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Delete cache manually

Hi

\Modules\Shared\Models\Match::findFirst(
'cache' => array( 
    'key' => 'match',
    'lifetime' => strtotime(date('Y-m-d 23:59:59'))
    )
);

I want to delete this cache manually in some cases. is it possible?



85.0k
Accepted
answer
edited Sep '14

You can obtain the modelsCache service and delete it manually from it:

$di->get('modelsCache')->delete("match");

Also, the lifetime must be the number of seconds the cache must live, passing a unix time like that would not work, you can pass the difference with the current time:

\Modules\Shared\Models\Match::findFirst(
'cache' => array( 
    'key' => 'match',
    'lifetime' => strtotime(date('Y-m-d 23:59:59')) - time()
    )
);
edited Sep '14

I also tried

$di->get('modelsCache')->flush();

works very good.

thanks :)