We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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?



98.9k
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 :)

eg: i want run function Phosphorum\Task\Cache::clear;

cli: php {projectPath}/forum cache clear


btlos bicycle