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

How view cache actually works?

Hi,

If we take example of album-o-rama application, in index action of the controller https://github.com/phalcon/album-o-rama/blob/master/apps/frontend/controllers/IndexController.php, the following code is used to generate key for caching

$offset = mt_rand(0, 1000);

$key = 'index'.$offset;

I m curious each time the application is refreshed won't it create the different cache file with name "index212, index765,...and so on". So I m wondering what is the point of cache if its creating different cache file everytime page is reloaded.

Please bear with me, I m a beginner.

Thanks



6.9k
Accepted
answer

I believe that part of the code is more to be shown as an example - If you check here https://github.com/phalcon/album-o-rama/blob/master/apps/frontend/controllers/IndexController.php#L29

it is used for basically 'randomly' selecting a albums based on the PK being higher than $offet * 30 - up to 1000 possible cache varients that will last for 1 day https://github.com/phalcon/album-o-rama/blob/master/public/index.php#L40