Forum Moderators: coopster

Message Too Old, No Replies

PHP Caching

How to limit disk space

         

polythene

9:57 pm on Sep 21, 2004 (gmt 0)

10+ Year Member



I want to use Cache_Lite to cache lots of small pieces of HTML, results of function calls, XML returned from web services, etc.

But how can I manage the disk space used for caching? Do I have to set up a job for this? Can I do it in the code? Or is there a way to let the OS manage it automatically?

Thanks

polythene

4:47 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



Really my question applies to any sort of PHP caching, not just with that specific package.

Surely lots of people have used caching to speed up their PHP, whether you rolled your own or downloaded a package. Coming from the ASP world I've used it to save copies of database query results, XML returned from web services calls, etc.

Regardless of what data is being cached:

1. Where do you store it? Disk, database, shared memory (not sure if possible with PHP, but easy in ASP with the application object)?

2. What methods do you use to clear out old cached bits in order to keep from running out of disk space, RAM, etc?

mincklerstraat

5:27 pm on Sep 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm also sort of new to caching. I use jpcache, a GPL 'drop-in' caching solution, tweaked a bit to do some extra things I want it to do. Jpcache is really very, very basic. I save my cache in files below the root directory, which is probably what you want to do if you use a file cache (next to memory cache, one of the fastest ways of caching).

Most cache managament systems will have their own 'garbage collection' system, which will typically be run every x times your script is run, just sort of randomly called every once in a while. I'd imagine that the main thing that garbage collection does is removes cached files which are expired.

In addition to caching your files locally, a good caching system will put you on the path toward making your scripts 3rd party cache friendly - so ISP's can have your pages cached, which of course will make your pages even faster, and reduce your bandwidth and server burden more. Jpcache went some of the way with its support of E-tags - although I believe I had to modify some code there to get things working well - I also wanted to add meaningful 'if-modified-since' headers, and respond to the 'if-modified' requests that were sent to pages. I don't remember if cachelite does this or not, I chose jpcache initially since it was so simple and lightweight, and I didn't really see the point in instantiating an object just to grab a cache page, thought the whole operation would be quicker with non-OO code for this. I need non-GPL code for what I'm doing, so I'll probably switch to smarty, cachelite, or roll my own later.

It seems that Turck mm cache is also really worth looking into if you're not on shared hosting. This would be a sort of memory cache.

jamie

6:07 pm on Sep 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi,

i've used cache_lite and as far as i know it doesn't have any auto routines to clear up the cache directory. i only cached a few things though, so the directory never got out of hand.

mincklerstraat,

cache_lite doesn't send any headers itself, it is only for caching bits of the page. you are still responsable for sending the correct headers.