Poor man’s cache for squirrelcart
I’m using squirrelcart currently for a client’s ecommerce site. They didn’t want anything fancy in the ecommerce realm, for their version (even though squirrelcart supports it) it doesn’t even connect up to someone like authorize.net to take payments. It has been great and easy to create a theme in. The 90-day support that comes with the purchase it is great. They have been very helpful while I get my feet on the ground.
An issue that I ran into was that once you start adding in a bunch of categories (I’m talking in the hundreds) things slow down. Noticeably. When I talked to support about it they felt that the response time was reasonable. For what I paid for the package I’m getting a phenomenal amount of help already so I don’t think it is all that bad for them not to be doing something in this area.
Still, the fact remains that as more categories get put into the system it will slow down. I don’t project that this client of mine will be having to deal with thousands of hits per minute, but as I’ve been watching search engines put more weight on how quickly a site responds I’d like it to at least maintain the responsiveness regardless of how the site grows over time.
Since most of the category pages on this site are static and don’t change very often, and especially since the root categories are the slowest ones, I decided to create a poor man’s cache for the site. One of my big concerns is that I don’t touch squirrelcart code. I don’t want to have to track how my changes do or don’t break across newer versions of it with patches and such.
Here’s what I do to get it to work:
- At the top of the store_main.tpl.php file I check to see if the page is a category or content page.
- If the page falls under one of those two groups I start php’s output buffering using ob_start()
- At the end of the page I check to see if this page is being buffered and save the file out to where it would be in the structure of the website as well as return the page as usual to the client
- In the .htaccess file at the root of the site I add in the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Basically what’s happening is I’m telling apache to check to see if the file exists first before going through the regular store.php file. If it does, it just returns back the static file that I already cached. If it doesn’t exist then it goes through the regular routines in the store.php and generates the cached file at the end so the next time the page is viewed it just serves up the file instead of having to go back and forth with the database and other processing logic.
The last piece of this is that I just have a simple script that I put in my theme folder to clear out the cached files for me. This is so when the client changes something they can tell the site it needs to start over. Sort of ham fisted I know but it is a poor man’s cache is it not? I also still get the added benefit of not touching squirrelcart’s source.
One thing I didn’t really cover is that I have a global variable called $is_caching that any of the template files can grab and set to ‘no-cache’ if they don’t want the page that they are generating to be cached. I then check in the store_main.tpl.php file for that global being set to no-cache and don’t do the caching routine. You have to do it that way because of the way that squirrelcart goes about pulling in the various pieces of a page, but it all works for my client’s needs! I was able to get a page that was loading at 17 seconds down to responding in less than 250 milliseconds. At that speed the only lag time you’re dealing with is probably via the network and disk I/O on the server.
-
endometriosisdg liked this
-
deborah90 liked this
-
dictionaryde2 liked this
-
security980dek liked this
-
tomjensen posted this