Caching¶
ASA2 uses two different caches to speed up page loading time:
Note
To put it simply: The Object Cache keeps the product item objects cotaining all the product data whereas the Template Cache keeps just the HTML output generated for a certain product.
Process Flow Chart¶
This flow chart illustrates what happens when an ASA2 shortcode is processed. It points out how and when the Template Cache and Object Cache are working.
Template Cache¶
You can activate the Template Cache on ASA2’s options subpage Cache. Learn more on options page Cache.
Generating the HTML output is not a big problem in terms of page loading speed unless you do not have huge templates, plenty of products on one page or a slow server. But using the Template Cache is highly recommended as it also prevents the product data objects from being created every time.
Note
It is highly recommended to use the Template Cache as it prevents the product data objects from being created on every page load.
The default cache lifetime for the Template Cache is 3600 seconds which is one hour. This means that ASA2 will load the generated HTML template from the cache for one hour until it will be generated again. You may adjust the lifetime to your demands, e.g. raise it to several hours. It is not recommended to raise the lifetime to more than one day.
To clear the Template Cache select the checkbox Clear template cache and submit the options.
Object Cache¶
You can activate the Object Cache on ASA2’s options subpage Cache.
ASA2’s Object Cache stores PHP objects representing the product data. Every time ASA2 handles a product, it creates a PHP object based on the XML result from Amazon’s API. If the requested product exists in the Products, ASA2 creates the object from the Repo result (request to the local database). Otherwise ASA2 will query the Amazon API which takes longest. It is therefore highly recommended that you activate the object cache.
If the Object cache is activated, ASA2 stores every created product object in it and retrieves the object from the cache for further requests within the cache lifetime. This is the most rapid way for ASA2 to retrieve the product data objects, because it avoids unnecessary requests to the API.
Note
It is highly recommended to use the Object Cache as it avoids unnecessary requests to the API.
The default cache lifetime for the Object Cache is 3600 seconds which is one hour. This means that ASA2 will load a prodcut data object from the cache for one hour until it will be generated again. You may adjust the lifetime to your demands, e.g. raise it to several hours. It is not recommended to raise the lifetime to more than one day.
To clear the Object Cache select the checkbox Clear object cache and submit the options.
Translation Cache¶
The translation cache speeds up loading the translation values used in internationalized templates (see: Translation). The values are stored in the database. For each unique translation key used in a template, one query to the database will be performed per page. Multiple requests for the same key on one page will be buffered even when delivered from the database. But with the cache activated, ASA2 puts the translation data into a text file and loads the data from this text file on further requests. This is much faster because it is just one request to a text file instead of several requests to the database.
With ASA2 Premium you can use other caching methods, like Memcache, which will speed things up even more.
Associate ID sets cache¶
With ASA2 you can manage multiple Amazon Associate IDs which is useful if you work with several country stores. When ASA2 renders an internationalized product (see Internationalization (i18n)), it requests the Associate ID sets from the database to find the matching ID. This has to be done for every internationalized product on a page resulting in several database requests.
To prevent those database requests, you can activate the Associate ID set cache. It will put the Associate ID sets data in a text file for further requests.
With ASA2 Premium you can use other caching methods, like Memcache, which will speed things up even more.
Ratings cache¶
In default mode, this cache is used to prevent ASA2 from trying to grab ratings from the Amazon site for the same product several times a day. This would be unnecessary and would greatly increase the risk of getting the captcha page.
In Advanced ratings mode, this cache is not used at all, since ASA2 then controls the frequency of attempts internally with a database table.
Caching lifetimes¶
You can set a custom lifetime in seconds for every cache. The default is 3600 (one hour). This means, ASA2 will load the data from the cache within this period. After the lifetime is exceeded, it will reload the data from its original source, e.g. the database, and refresh the cache again.
Note
It is not recommended to set a lifetime higher than one day.
The lifetime should not be set to a value more than some hours. For example, the customers reviews URL, delivered by the API, is valid for only 24 hours. If you would set the template cache to more than one day, after 24 hours {{ CustomerReviewsURL }} will not work any more.
Ignoring the Cache¶
Sometimes caching may be annoying, for example if you are working on a new template design on a test page. In this case you do not have to deactivate the cache completely. You can tell ASA2 to ignore the cache by using the no_cache
shortcode option. It affects both the Template and the Object cache. See the Shortcodes pages for more details.
[asa2 no_cache="1"]B0094J2BZ0[/asa2]
[asa2_collection tplid="16" no_cache="1"]
[asa2_smart_collection s="LEGO" cat="13,34,56" no_cache="1"]
Deactivate cache for admin¶
When setting up new products, templates or translations on a site, it might be inconvenient to use caching, because changes will not be loaded. If you activate the option “Deactivate for admin” on the option’s “Cache” panel, every cache will be ignored if you are logged in as admin.
Resetting the caches¶
On the options page in section “Cache”, you can either hit the “Clear cache” button for a dedicated cache, to clear it, or hit the button “Clear all caches” to clear them all.
Options¶
For more details about the caching options, please refer to options page Cache.