The Memory caching system is geared to hold needed information available quickly.

There are a number of limitations you have to deal with, when working with the Memory Cache.

Number One, you cannot put arbitrary keys into the cache. Since the memcached php extension does not support key listings, you are bound to use MidCOM object GUIDs as cache keys, whatever you do. To allow for different subsystems of the Framework to share the cache, I have introduce "Data groups", which are suffixes for the actual cache information. Thus, all keys in the cache follow a "{$datagroup}-{$guid}" naming scheme. These groups need to be registered in the MidCOM configuration key cache_module_memcache_data_groups.

Number Two, it is entirely possible (as it is the default), that the memcache is actually not available, as no memcache daemon has been found. This is controlled by the cache_module_memcache_backend configuration option, which defaults to null. If it is set to the name of a caching module (normally memcached) it will actually start caching. Otherwise it will silently ignore put requests, and reports all keys as not existent.

Number Three, as at least memcached does not provide key_exists check, key values of false are forbidden, as they are used to check a keys existence during the get cycle. You should also avoid null and 0 members, if possible, they could naturally be error prone if you start forgetting about the typed comparisons.

Special functionality

  • Interface to the PARENT caching group, has a few simple shortcuts to the access the available information.
package midcom.services

 Methods

_on_initialize ()

Initialization event handler.

It will load the cache backend.

Initializes the backend configuration.

exists (string $data_group, string $key)

Checks for the existence of a key in the cache.

Parameters

$data_group

stringThe Data Group to look in.

$key

stringThe key to look up.

Returns

booleanIndicating existence

get (string $data_group, string $key)

Looks up a value in the cache and returns it.

Not existent keys are caught in this call as well, so you do not need to call exists first.

Parameters

$data_group

stringThe Data Group to look in.

$key

stringThe key to look up.

Returns

mixedThe cached value on success, false on failure.

invalidate (string $guid)

Invalidates the GUID for all known data groups.

Parameters

$guid

stringThe GUID to invalidate.

lookup_parent_data (string $guid)

This is a little helper that tries to look up a GUID in the memory cache's PARENT data group.

If it is not found, false is returned. If the object has no parent, the array value is null

Parameters

$guid

stringThe guid of which a parent is searched.

Returns

arrayfalseThe classname => GUID pair or false when nothing is in cache

put (string $data_group, string $key, mixed $data, int $timeout)

Sets a given key in the cache.

If the data group is unknown, a Warning-Level error is logged and putting is denied.

Parameters

$data_group

stringThe Data Group to look in.

$key

stringThe key to look up.

$data

mixedThe data to store.

$timeout

inthow long the data should live in the cache.

update_parent_data (string $object_guid, array $parent_data)

This is a little helper that saves a parent GUID and class in the memory cache's PARENT data group.

Parameters

$object_guid

stringThe guid of which a parent is saved.

$parent_data

arrayThe guid and classname of the parent which is saved.

 Properties

 

Array $_backend

The configuration to use to start up the backend drivers.

Initialized during startup from the MidCOM configuration key cache_module_nap_backend.

 

\midcom_services_cache_backend $_cache

The cache backend instance to use.
 

Array $_data_groups

List of known data groups.

See the class introduction for details.