Page Cache

Introduction

One of the primary features of NitroPack is the page caching mechanism. It is used to speed up the response time/TTFB (Time To First Byte). Here is how it works:

  1. A page on your website is visited for the first time. OpenCart runs as usual (executes PHP code, runs and waits for MySQL queries) and generates the needed HTML. NitroPack captures this HTML before it is sent to the client and saves it in a cache file under the system/nitro/cache/pagecache/ directory.

  2. A consecutive visit (by the same client or anybody else, even bots) to the same page is made, but this time NitroPack intercepts the connection and responds with the cached HTML skipping the time that OpenCart would have otherwise needed to execute PHP, wait for MySQL queries and generate the HTML. This results in a lightning-fast response.

NitroPack page cache is a fast render output cache mechanism that serves already processed content directly to your visitors. The cache is generated per page, meaning that each cache file corresponds to the HTML of a single page. A cache file is created only when a page is being visited for the first time, so if some pages are never visited, they will not be cached. The first page visit is when the cache is created and any consecutive visits are served from the cache.

The cache is global, meaning that it does not matter which visitor will be the first one to cache a page, all future visitors will benefit from the cache.

Page cache saves the cached content in the following directory:

system/nitro/cache/pagecache/

Your PHP user needs to have write permissions in this directory in order for page cache to be created.

ImportantBefore enabling the NitroPack page cache, make sure that all other third-party page cache solutions are disabled. Otherwise, you might come across unexpected behavior.

Configuration

To configure NitroPack page cache, visit your OpenCart Admin Panel > Nitro > Settings > Cache Systems > Page cache. You will see the following configuration fields:

page_cache

1. Page Cache Status (Enabled / Disabled) - This switch controls whether page caching is enabled or disabled.

NoteA great deal of HTML optimizations (described further in this document) which NitroPack can do automatically are done only over the HTML saved in cache files. The reason for this is that these optimizations take some time to apply, so it is not practical to make them on pages which are not going to be cached. However this means that if Page Cache is disabled these features will stop working as well. Examples are the HTML minification, HTML compression, HTML browser cache, the automatic definition of width and height attributes, combining and positioning of CSS and JavaScript resources.

2. Expire Time (Integer, representing number of seconds) - If the cache files get older than this time period, they will be re-cached automatically. Default value is 86400 which represents 1 day in seconds. It is a common practice to extend this to 1 week or 1 month. The value for 1 week is 604800 and the value for 1 month is 2592000.

3. Responsive theme optimizaiton (Enabled / Disabled) - By default NitroPack creates separate cache files each of the three main versions of your site (Desktop, Tablet, Mobile), because they may have different HTML. If your theme is responsive and you know that the HTML is the same regardless of the device type - Enable this option. It will tell NitroPack that it can use 1 file instead of 3, which saves disk space and CPU time.

4. Add width/height attributes to images (Enabled/Disabled) - Enabling this helps for faster image rendering by your browser. It adds width and height attributes to the <img> tags inside of the cached HTML. This speeds up the rendering time on your customers' browsers.

NoteThis option is not compatible with some OpenCart themes. If your images get stretched because of this option, it is recommended to disable it.

page_cache1

5. Clear cache on product edit (Enabled / Disabled) - When enabled, the page cache for a specific product will be cleared automatically on one of the following conditions:

- After you modify this product from the admin panel

- After a customer purchases this product

- After you edit an order containing the product

NoteYour MySQL user must have CREATE and ALTER permissions in order for this feature to work. If your MySQL user does not have CREATE and ALTER permissions, keep this feature disabled.

If you are not sure whether your MySQL user has the required permissions, simply enable the option and check whether this will generate any error messages. In most cases you will not have issues with this option.

6. Ignored Routes (OpenCart routes, separated line by line) - If you do not want to have page caching for certain routes in your store, list them here. One route per line. Example: common/home

7. Supported cookies (cookie names, separated line by line, wildcards are supported) - sometimes different HTML is being generated based on a value of a cookie. An example is a cookie policy notice. If the client has not accepted the policy, a notification is displayed, otherwise the notification is not displayed. This is controlled from a cookie which name starts with header_notice. In order to make NitroPack behave correctly in this case, you need to add the cookie name (or part of it) to the supported cookies setting. Because the complete cookie name for the header notice module is something similar to header_notice_ac8rO and the ac8r0 part is dynamic we have to use wildcard to support it. To support the header notice cookie you need to add the following in the supported cookies field: header_notice*.

8. Store Front Widget (Show only for admin / Show always / Show never) - This setting controls when to display the store front widget. The widget is a small stripe in the very bottom of the screen, which is displayed for pages that have been served from the cache. It shows useful data like how fast did NitroPack serve the page and how much faster was that compared to the default loading speed without NitroPack. It also allows you to clear the cache for the current page only by clicking the green Clear Cache button on the right side of the widget. Here is how the stripe looks like:

widget

Here is how the options for this setting work:

  • Show only for admin: The widget will be displayed only to admins, so regular users will not be seeing it (this is the default setting)
  • Show always: The widget will be displayed to everybody
  • Show never: The widget will never be displayed

Limitations

There are some cases, when it would be more beneficial to serve non-cached content to your visitors. In the following cases, NitroPack page cache is deliberately disabled:

  1. If your customer is logged into their account - Page cache needs to be disabled for this case, because almost all of the stores display a different header for each user (containing username, items in cart, etc.).

  2. If your customer has items in the shopping cart - Same as above, having an item in your shopping cart will lead to different front-end content, which is better to remain non-cached.

  3. If your customer has items in the wishlist - Same as in point 1, having an item in your wishlist will lead to different front-end content, which is better to remain non-cached.

  4. If your customer is visiting an ignored route - They can be configured in OpenCart Admin Panel > Nitro > Settings > Cache systems > Page cache > Ignored Routes.

  5. If your customer is visiting an ignored URL - They can be configured in OpenCart Admin Panel > Nitro > Settings > Settings > Disable NitroPack for specific pages.

  6. If Maintenance mode is enabled in your store - In this case, we need to make sure that the Maintenance page will be served to your customers, instead of a cached page.

  7. If the request is AJAX - AJAX requests in almost all cases return different content, which is why they should not get cached. This also allows you to use AJAX to implement dynamic content for cached pages.

  8. If the request is POST - POST requests are used when the client needs to send information to the server which must be processed. This is why we need to let OpenCart handle these requests normally in order to preserve proper site operation.

  9. If the customer has an YMM filter selected - YMM is a third-party module, which allows your customers to filter products based on Year, Make and Model. More information about YMM can be found here: http://www.opencart.com/index.php?route=extension/extension/info&extension_id=3621

  10. If the customer has AbandonedCarts enabled for his IP address.

Page cache is also automatically disabled for the following routes, since they always display dynamic content:

Route Route
checkout/cart account/voucher
checkout/checkout account/transaction
checkout/success account/newsletter
account/register account/logout
account/login affiliate/login
account/edit affiliate/register
account/account affiliate/account
account/password affiliate/edit
account/address affiliate/password
account/address/update affiliate/payment
account/address/delete affiliate/tracking
account/wishlist affiliate/transaction
account/order affiliate/logout
account/download information/contact
account/return product/compare
account/return/insert error/not_found
account/reward api/*

Pre-caching of content

Because the cache is created on the first page visit, this means that the first visitor for a page will not get the cache benefits like the rest. The NitroPack pre-caching tool is an optional way to simulate the first-visitor of your store to create the cache, so all visitors can benefit from the cache later on. It is not required to run this tool after each clear cache, but when you use it, it will make the cache serving to the first visitor of your store possible, since the cache will be already created for them.

In order to use Pre-cache, please visit OpenCart Admin Panel > Nitro > Settings > Cache systems > Page cache and click the button Pre-cache sitemap pages. The pre-cache process will start afterwards.