by Chemo
This contribution creates a cache of each page and will use that pre-compiled copy if it is not expired. The settings are integrated into the admin control panel and can be easily modified. Current settings are:
- Enable Page Cache - Turns the page cache contribution on and off
- Page Cache Lifetime - Sets the time (in minutes) that the cache is valid
- Enable Global Debug Mode - Turn on debug output GLOBALLY (can be enabled for ONLY your browser)
- Disable URL Parameters - Disables URL parameters for live help appended parameters, etc.
- Delete Cache Files - Deletes all the cache files on next page load
- Configuration Cache Update File - If a configuration setting cache contribution is used this will include that file and update automatically
Advantages
- MAJOR performance increase
- Lower server load
- Faster page renders
- Items in cart are STILL dynamically generated
- Multi-language and currency support
Disadvantages
- Cache copy is served ONLY to guests
- Dynamic portions of site change when page cache expires (specials, featured, etc.)
This contribution first checks whether the visitor is a guest and the page cache is enabled. If so, it then checks to see if a cache copy of the page exists and renders that if true. The shopping cart information (items in cart) is generated and replaced into the cache copy so each visitor has a dynamic page.
A page can be cached by adding the code to the bottom and top of the pages. Suggestions would be: index.php and products_info.php since these are the most viewed on a typical store.
It should be noted that REGISTERED CUSTOMERS will not receive a cache copy and will ALWAYS get a fully parsed page.
All values are given as averages of 100 hard refresh page loads (CTRL + F5)!
Before Cache
Page Parse Time Queries index.php .398 s 28 Category Listing .602 s 56 Product Page .441 s 42
After Cache
Page Parse Time Queries index.php .118 s 10 Category Listing .132 s 11 Product Page .124 s 13
Click on the links and scroll to the bottom of the page. The screen shots were taken from this site. Links open in new browser.
Integration to Admin Control Panel
![]()
STEP 1 - Upload the file (new so should not overwrite anything)
The only file to be uploaded is *catalog*/includes/classes/page_cache.phpSTEP 2 - Create a new directory at your root called "cache"
Future versions will make this a setting that can be changed via the admin control panel but for now it is hard coded. If called in an URL it should look like http://yourstore.com/cache/
Make sure that the web server has read/write permissions! Use an FTP program or console (SSH) to CHMOD the directory.
STEP 3 - From phpMyAdmin or other convenient method execute the SQL file.
The SQL file is called page_cache.sql and is located in the sql directory of this contribution.STEP 4 - Edit includes/application_top.php
Add this to the bottom of includes/application_top.php just above the "?>" closing tag:
STEP 5 - Edit includes/application_bottom.php
Find this code:
And ABOVE that add this:
STEP 6 - Edit includes/functions/html_output.php
Find this code in tep_href_link():
And REPLACE it with this code:
Find this code in tep_href_link():
And REPLACE it with this code:
STEP 7 - Edit includes/column_right.php (or wherever you have the shopping cart displayed)
Find this code:
And REPLACE it with this code:
STEP 8 - Enable the contribution from the admin control panel
The only thing left to do (after saving the file changes) is to enable it via the admin control panel. There is now a section under configuration called "Page Cache Settings". Modify the settings per your requirements and check out the speed improvement. Remember, the first page load creates and stores the cache so there will not be a speed difference. However, on subsequent requests it should improve the page render time considerably.
- Remove the old page cache code from applicaton_top.php, index.php, and product_info.php
- Perform steps 4 and5
- Upload and overwrite the new class (includes/classes/page_cache.php)
osCommerce is a community driven organization and as such the support base will fall entirely on the forum members. The base class is thoroughly commented and should be easy to follow for any coder. I offer limited support in-between paid projects (feeding my family comes first before volunteer time).
If you use this contribution and find it useful a small donation can be made via PayPal. This will enable me to offer one-on-one support and also fund releasing other contributions. In addition, if you make a donation it'll make you eligible for other performance optimization contributions that are not released!
This contribution is original work and nothing is borrowed. Enjoy!