PHP cache implementation with maximum cache folder size

There. I need to implement a cache for my PHP web application. I implemented a cache control (saving and retrieving files from the dir cache), but now I need to ensure the maximum cache size, since the cache folder should be limited to the maximum size.

I had the idea to limit the size by deleting the least used files when this space is needed. Now I read that using the fileatime function in all files in the cache will slow down my application.

Is there any other method that arises in your mind?

(Using DB (MySQL) to store the last access time for cache files, unfortunately, is not implemented.)

+3
source share
1 answer

Why not use a cron job that clears every hour?

Any verification that you do in each request will be expensive.

If this is not possible, saving a central text file to store the modification time may be the best way, but you have encountered blocking problems.

+3
source

Source: https://habr.com/ru/post/1752796/


All Articles