Cache File Locking
August 4, 2000
I'm performing some complex SQL selects to generate some of these cached
modules. Some of them are taking longer than I would like, but priorities
demand that I concentrate on tasks other than database performance. I
simply added some cron tasks to automate the refreshing of modules in
coordination with their tag REFRESH tag. The cron tasks simply
request the page from the web server.
However, I was concerned with multiple users hitting the server initiating
redundant SQL executions, which would unnecessarily increase the load on
the database.
I used a simple locking solution. If the script determines that a cache
file needs to be updated, it creates a lock file that indicates the cache
file is already being generated. Subsequent requests for that same cache
file notice that the lock file exists and wait until that lock file is
removed by the initial script and then grabs the cache file when it finishes.
Hopefully, with these enhancements, this solution becomes even more
powerful while making it easier to implement for the developer.
You should be able to cut and paste it into your own solution.
Manual Cache File Naming
Another Look At "Building Your Website With Cached Dynamic Modules"
The Full Code
|