Pimcore and the cache
Pimcore uses extensively caches, for differently types of data. The primary cache is a pure object cache, every element (document, asset, object) in pimcore is cached as it is (serialized objects). Every cache item is tagged with dependencies so the system is able to evict dependent objects if the referenced object changes.
The second cache is the output cache, which you can use either as pure page cache (configureable in system settings), or as in-template cache (see more at template helpers).
The third cache is used for add-ons like the glossary, translations, and so on. The behavior of the caches is controlled by the add-on itself.
Contents
Disable the cache for a single request
Sometimes it's useful to deactivate the cache for testing purposes for a single request. You can do this by passing the parameter nocache. Note: This is only possible if you have enabled the DEBUG MODE in Settings -> System
For example: http://www.pimcore.org/download?nocache=true
This will disable the entire cache, not only the output-cache, to disable only the output-cache you can add this parameter: ?pimcore_outputfilters_disabled=true
You can find more "magic parameters" here.
If you want to disable the cache in your code, you can use:
Pimcore_Model_Cache::disable();
This will disable the entire cache, not only the output-cache. WARNING: Do not use this in production code!
It is also possible to just disable the ouput-cache in your code, read more here.
Setup a custom caching-backend
Pimcore uses by default the Zend_Cache_Backend_File backend for caching. This backend isn't very powerful and speedy particulary when there is a huge amount of items to cache, or your'e using a SAN as storage (the cache creates a very large amount of files).
You can use every implementation of Zend_Cache_Backend which supports tags, you can also use your own cache backend.
Because the memcache backend shipped with ZF doesn't support tags, pimcore offers a special implementation of the memcache backend (Pimcore_Cache_Backend_Memcached), which stores the tags into a MySQL table. If you want to use this implementation just have a look at the following example:
Enable a custom cache
To enable a custom cache backend you have to create a new file: /website/var/config/cache.xml, there is already a example cache configuration in /website/var/config/cache.xml.example
Example for the pimcore memcache backend:
pimcore memcache backend
<?xml version="1.0"?> <zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/"> <backend> <type>Pimcore_Cache_Backend_Memcached</type> <custom>true</custom> <options> <servers> <host>localhost</host> <port>11211</port> <persistent>true</persistent> <compatibility>true</compatibility> </servers> </options> </backend> </zend-config>
custom file backend
<?xml version="1.0"?> <zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/"> <backend> <type>File</type> <options> <cache_file_umask>0755</cache_file_umask> <cache_dir>/www/pimcore/www/website/var/cache</cache_dir> </options> </backend> </zend-config>
Setup a custom cache frontend (e.g. for memcache with id-prefix)
You can also define a custom cache frontend, this can be also done in the cache.xml
In this case we configure the memcache backend (with tagging support) which is part of the pimcore distribution.
<?xml version="1.0"?> <zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/"> <frontend> <type>Core</type> <options> <cache_id_prefix>pimcore_dev</cache_id_prefix> <lifetime>99999</lifetime> <automatic_serialization>true</automatic_serialization> </options> </frontend> <backend> <type>Pimcore_Cache_Backend_Memcached</type> <custom>true</custom> <options> <servers> <host>memcachehost1</host> <port>11211</port> <persistent>true</persistent> <compatibility>true</compatibility> </servers> <servers> <host>memcachehost2</host> <port>11211</port> <persistent>true</persistent> <compatibility>true</compatibility> </servers> </options> </backend> </zend-config>