Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing PHP cache with maximum size of cache folder

Tags:

php

caching

Hy there. I need to implement cache for my PHP web application. I implemented the cache file control (saving and getting files from cache dir) but now I need to enforce cache folder max size control, because cache folder should be limited in max size.

I had an idea to limit the size by deleting the least used files when the space is needed. Now, I've read that using the fileatime function on all the files in cache dir would slow down my application.

Is there any other method that springs in your mind?

(DB (MySQL) usage for storing last access time for cache files is, unfortunately, unimplementable.)

like image 628
Stazh Avatar asked May 25 '26 02:05

Stazh


1 Answers

Why not use a cron job that cleans up every hour?

Any check you make in every request is bound to be expensive.

If that isn't possible, keeping a central text file to store the modification times might be the best way, but you're going to get locking problems.

like image 94
Pekka Avatar answered May 27 '26 16:05

Pekka