Incapsulates LemonStand caching API features.
This is an interface class for the caching API. The caching API supports 3 caching providers -
file-based,
memcached and
APC. Please read
Caching API documentation article to learn more
about LemonStand caching features and configuration. The following example demonstrates a typical
usage of the class:
$cache = Core_CacheBase::create();
// Try to load the item value from the cache
$recache = false;
$key = Core_CacheBase::create_key('some_item', $recache, array('url'), array('cms','catalog'));
$value = $cache->get($key);
// If the key has expired, or if there is no item with this key stored (or if it has expired),
// generate new item value and cache it
if ($recache || $value === false)
{
$value = 'value';
$cache->set($key, $value);
}
Returns an instance of the cache class.
Depending on the configured caching provider, the method returns an object of the
Core_FileCache, Core_MemCache or Core_ApcCache class. All these classes has same
methods.
Allows to create item keys, which depend on different current conditions.
Use this function for creating keys, which expire depending on the catalog content state,
current customer group and some other conditions.
The
$vary_by parameter allows you to specify which conditions the key value should
depend on. The condition list could include system conditions, or custom conditions. The
known system vary-by parameters are:
- url - generates different keys for different page URLs.
- customer - generates different keys for different customers.
- customer_group - generates different keys for different customers groups.
- customer_presence - generates different keys depending on whether a customer is logged in or not.
The system vary-by parameters should be specified as strings. You can also specify any other parameters
you want the key to depend on. These parameters should be specified as key-value pairs, see the order example below.
The
$versions parameter allows you force the item recaching when the store content updates.
There are 3 content types which you can specify in the parameter value. If any of the specified content types
updates, the method assigns the TRUE value to the
$recache parameter. You can use the following
version content types:
- cms - forces recaching if any CMS object (page, partial or template) has been added, updated or deleted.
- catalog - forces recaching if any catalog object (product, category, etc.) has been added, updated or deleted.
- blog - forces recaching if any blog object (post, category or comment) has been added, updated or deleted.
Examples of the create_key() method usage:
// Create key, which does not depend on any parameter.
// There is no real sense in using the create_key() function in this case.
$recache = false;
$key = Core_CacheBase::create_key('some_item', $recache);
// Create key, which depends on the page URL and the CMS content version.
// Notice that if you use only a single value in the $vary_by and $versions parameter,
// you can specify values as string.
$recache = false;
$key = Core_CacheBase::create_key('some_item', $recache, 'url', 'cms');
// Create key, which depends on the page URL, and customer group. Thus, the key will be
// different for different pages and different customer groups. Also, the key will
// expire on the CMS or catalog updates.
$recache = false;
$key = Core_CacheBase::create_key('some_item', $recache, array('url', 'customer_group'), array('cms','catalog'));
// Create key, which depends on the sort order variable. We will be getting different
// keys for different sort order values.
$recache = false;
$sort_order = 'name asc';
$key = Core_CacheBase::create_key('some_item', $recache, array('sort_order'=>$sort_order));
$sort_order = 'name desc';
$key = Core_CacheBase::create_key('some_item', $recache, array('sort_order'=>$sort_order));
Returns value from the cache.
Adds or updates value in the cache.