Quote:
|
Originally Posted by mikesmith76
Does anyone on here implement caching on their site using their own code?
|
Yes.
Within our directory script we build the category pages leaving markers where dynamic content such as ads go. This semi complete page is then stored in the database.
One query gets the page leaving just the dynamic content to be populated. You could store the data in the file system if you prefer.
Pages are dropped from the cache when their content changes in some way. The next time the page is viewed the page is rebuilt and cached, this lazy caching saves waiting for several thousand pages to rebuild.
The directory script tries to limit the number of pages that are dropped from the cache due to a change, it will try and just drop the changed page and it's parents leaving it's siblings cached. This is somewhat specific to the structure of a directory compared with what you are trying to do.
Quote:
|
How can i stop someone accessing the cache while it is being recreated? can the php function flock be relied upon to give an exclusive lock on a file? For those of you that have implemented similar solutions how did you resolve these issues?
|
flock should be fine. You might want to benchmark some tests though because if you lock too much you could find it becomes slower under load than running the queries.
We chose to store the data in the database because it makes it easy to distribute to multiple front end web servers, as and when the need arises. It also saves worrying about flock etc as the database does that for you.
Also we don’t worry if a page is regenerated for the cache by 2 visitors looking at it at the same time, one will overwrite the other, yes it wastes some time but it saves a table lock thus allowing other pages to continue to be used, generated and cached in parallel.
mmcache and eaccelerator are basically the same product just eaccelerator is the continued development. There's an option to use its extensions to store blocks of data into its cache. However you still need your own code to create the page, build the data to cache, put the data in the cache and to restore and paint the cached data.
From memory I don’t think they offer persistent caching but rather after some time frame cached objects are deleted, therefore this might not be the best solution for caching pages.
Is it worth the effort to save 1 or 2 queries per page? Probably not. If you have that amount of traffic that saving 2 queries is important then maybe you should:
a) Look to see if you can optimise the database, maybe create a secondary table or index so that a single query can retrieve all the data.
b) Place a reverse proxy cache in front of apache,
http://www.visolve.com/squid/whitepa...verseproxy.php
Be careful of over optimising.