Page Cache v1.6 for osCommerce-ms2

by Chemo

What does this contribution do?

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:

Advantages

Disadvantages

How does this contribution work?

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.

What kind of speed improvements can I expect?

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

Online Demo Site (Live Shop - don't buy)

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.

Screen Shots

Integration to Admin Control Panel

How do I install this contribution?

Upload 1 file, execute 1 SQL file, modify 4 existing files, done. Install should take about 5 minutes.

STEP 1 - Upload the file (new so should not overwrite anything)

The only file to be uploaded is *catalog*/includes/classes/page_cache.php

STEP 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.

How do upgrade this contribution from versions 1.0 - 1.3?

Support

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!

Enter Donation amount: $

Credits

This contribution is original work and nothing is borrowed. Enjoy!