This is the API docs for LemonStand V1, which has been discontinued. LemonStand is now a cloud based platform, available at lemonstand.com.

LemonStand API

Core_CacheBase class

Defined in /modules/core/classes/core_cachebase.php, lines 32-289
Author LemonStand eCommerce Inc.
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);
}

See Also

Public methods

Method Description Defined By
create() returns an instance of the cache class. Core_CacheBase
create_key() allows to create item keys, which depend on different current conditions. Core_CacheBase
get() returns value from the cache. Core_CacheBase
set() adds or updates value in the cache. Core_CacheBase

Method details

create() method

public static mixed create()
{return} mixed returns a cache class instance.
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.

create_key() method

public static string create_key(string $prefix, boolean &$recache, array $vary_by=array(), array $version=array())
$prefix string a prefix string. If you omit the the $vary_by and $versions parameters, the method always returns the same key value, based on the prefix value.
$recache boolean indicates whether the item should be recached. Recaching should be required if you specify any content type in the $versions parameter.
$vary_by array determines which conditions the key value should depend on.
$version array allows to force the recaching when the store content updates.
{return} string returns the new item key.
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));

get() method

public mixed get(mixed $key)
$key mixed specifies the item key to fetch.
{return} mixed returns the item value or FALSE if the item was expired or not found.
Returns value from the cache.

set() method

public bool set(string $key, mixed $value, integer $ttl=NULL)
$key string specifies a key that will be associated with the item.
$value mixed specifies the value to store.
$ttl integer specifies the number of seconds the value should stay in the cache. When an item expires its gets expunged from the cache (on the next request). If no ttl is supplied (or if the ttl is 0), the value will persist until it is removed from the cache manually.
{return} bool returns TRUE on success or FALSE on failure.
Adds or updates value in the cache.