tags:

views:

15

answers:

1

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.)

+2  A: 

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.

Pekka
The cron job method works very nice, and you can make in such way that if the webserver is really busy then you may "skip" a cleanup and wait until the cronjob starts again and the server is less busy... basically you have more control and more speed
Quamis