.. include:: _include.rst .. highlight:: bbcode .. _caching: ############################ Caching ############################ |productabbr| uses two different caches to speed up page loading time: - :ref:`template_cache` - :ref:`object_cache` - :ref:`translation_cache` - :ref:`associateidsets_cache` - :ref:`ratings_cache` .. 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 |productabbr| shortcode is processed. It points out how and when the Template Cache and Object Cache are working. .. image:: _static/cache.png :height: 1009px :width: 889px :scale: 100% :alt: ASA 2 Cache diagram .. _template_cache: ************** Template Cache ************** You can activate the Template Cache on |productabbr|'s options subpage **Cache**. Learn more on options page :ref:`options_cache`. .. image:: _static/cache_template_options.png :height: 262px :width: 701px :scale: 100% :alt: Template cache options 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 |productabbr| 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: ************** Object Cache ************** You can activate the Object Cache on |productabbr|'s options subpage **Cache**. .. image:: _static/cache_object_options.png :height: 195px :width: 680px :scale: 100% :alt: Object cache options |productabbr|'s Object Cache stores PHP objects representing the product data. Every time |productabbr| handles a product, it creates a PHP object based on the XML result from Amazon's API. If the requested product exists in the :ref:`repo`, |productabbr| creates the object from the Repo result (request to the local database). Otherwise |productabbr| 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, |productabbr| 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 |productabbr| 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 |productabbr| 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: ***************** Translation Cache ***************** The translation cache speeds up loading the translation values used in internationalized templates (see: :ref:`templates_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 |asa2pro| you can use other caching methods, like **Memcache**, which will speed things up even more. .. _associateidsets_cache: *********************** 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 :ref:`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 |asa2pro| you can use other caching methods, like **Memcache**, which will speed things up even more. .. _ratings_cache: *********************** 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 :ref:`ratings_advanced_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 |productabbr| to ignore the cache by using the ``no_cache`` shortcode option. It affects both the Template and the Object cache. See the :ref:`shortcodes` pages for more details. .. code:: [asa2 no_cache="1"]B0094J2BZ0[/asa2] .. code:: [asa2_collection tplid="16" no_cache="1"] .. code:: [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. .. image:: _static/cache_deactivate_for_admin.png :height: 49px :width: 692px :scale: 100% :alt: Deactivate cache for 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. .. image:: _static/cache_clear_buttons.png :height: 339px :width: 672px :scale: 100% :alt: Clear cache buttons ******* Options ******* For more details about the caching options, please refer to options page :ref:`options_cache`.