Cache

Cache access object factory. Normally the cache configs and object names are defined in the app config array or ini file, "$object-name = Cache::get('object-name');" will return the cache access object on demand.
Since
1.2.2

Static Methods

config

array|string Cache::config(string objectName=null, string index=null, array configs=null)

Set or get configs for a cache access object. The configs will only be set if a last param is passed. The configs are stored in "Arta::$cacheConfigs" which also contains the app cache object configs (from the app config ini file or array).

Arguments

    objectName=null (string)
    The object name to set or to get configs for, null=return all object configs
    index=null (string)
    Config key, to get the value of a specific setting
    configs=null (array)
    To add a new cache object configs
    {
        string engine : cache engine apc, e.g. xcache, memcached, memcache,
        string host   : (only for memcache) Memcache host only for memcache,
        string port   : (only for memcache) Memcache port,
        string 1      : (only for memcache) 'host1 port1' balance1,
        string 2      : (only for memcache) 'host2 port2' balance2,
    }
    

Returns

array|string
{configs} or {object-name: {configs},} or the value of a config key

get

ICacheAbstract|array Cache::get(string | bool objectName=null, bool remove=false)

Creates and returns or returns an already created object. When creating a new object the object configs are expected to exists in "Arta::$cacheConfigs", note that the cache objects defined in the app config array or ini file are put in "Arta::$cacheConfigs" by Artaengine.
Get a cache access object by passing the object name.
Get all cache access objects in an array by passing true.
To remove an object pass true for the second argument.

Arguments

    objectName=null (string | bool)
    Object name to create or to get handle of, null=return the last object in the list, true=return all objects
    remove=false (bool)
    true=remove/unsset the object

Returns

ICacheAbstract|array
Reference to a cache access object or a list of cache access objects

Throws

getCreateNew

ICacheAbstract Cache::getCreateNew(string objectName, array configs)

Creates and returns an object. Use this method to create a new object by passing the object configs versus "get()" that expects the configs to exist in "Arta::$cacheConfigs".

Arguments

    objectName (string)
    The object name to be created
    configs (array)
    Cache object configs
    {
        string engine : cache engine apc, e.g. xcache, memcached, memcache,
        string host   : (only for memcache) Memcache host only for memcache,
        string port   : (only for memcache) Memcache port,
        string 1      : (only for memcache) 'host1 port1' balance1,
        string 2      : (only for memcache) 'host2 port2' balance2,
    }
    

Returns

ICacheAbstract
Reference to the newly created cache access object

Throws

remove

void Cache::remove(string objectName)

Remove an object if already been created.

Arguments

    objectName (string)
    Object name to remove

Returns

void