\midcom_services_cache_module_memcache

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 tries to auto-detect a sensible default. If it is set to the name of a caching module it will actually start caching. Otherwise it will silently ignore put requests, and reports all keys as not existent.

Number Three, as at least memcache's contains() check isn't working on some machines, 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.

Summary

Methods
Properties
Constants
initialize()
shutdown()
_on_initialize()
_on_shutdown()
invalidate_all()
invalidate()
is_operational()
get()
put()
lookup_parent_data()
update_parent_data()
No public properties found
No constants found
_create_backend()
$_backends
$_prefix
N/A
prepare_backend()
$_data_groups
$_cache
N/A

Properties

$_backends

$_backends : array<mixed,\Doctrine\Common\Cache\CacheProvider>

A list of all backends created by _create_backend(). They will be automatically shut down when the module shuts down. They are indexed by their name.

Type

array<mixed,\Doctrine\Common\Cache\CacheProvider>

$_prefix

$_prefix : string

The cache key prefix.

Type

string

$_data_groups

$_data_groups : Array

List of known data groups. See the class introduction for details.

Type

Array

$_cache

$_cache : \Doctrine\Common\Cache\CacheProvider

The cache backend instance to use.

Type

\Doctrine\Common\Cache\CacheProvider

Methods

initialize()

initialize() 

Initialize the module. This will initialize the class configuration and call the corresponding event handler.

shutdown()

shutdown() 

Shuts the module down. This will call the corresponding event handler

_on_initialize()

_on_initialize() 

Initialization event handler.

It will load the cache backend.

Initializes the backend configuration.

_on_shutdown()

_on_shutdown() 

Shutdown handler, called during midcom_application::finish(). Note, that for example the page cache will not use this cleanup handler, as it produces a complete html page based on a previous request.

invalidate_all()

invalidate_all() 

Invalidate the cache completely, dropping all entries. The default implementation will drop all entries from all registered cache backends using CacheProvider::flushAll().

Override this function if this behavior doesn't suit your needs.

invalidate()

invalidate(string  $guid, object  $object = null) 

Invalidate all cache objects related to the given GUID.

Parameters

string $guid

The GUID that has to be invalidated.

object $object

The object that has to be invalidated (if available).

is_operational()

is_operational() 

get()

get(string  $data_group, string  $key) : mixed

Looks up a value in the cache and returns it. Not existent keys are caught in this call as well

Parameters

string $data_group

The Data Group to look in.

string $key

The key to look up.

Returns

mixed —

The cached value on success, false on failure.

put()

put(string  $data_group, string  $key, mixed  $data, integer  $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

string $data_group

The Data Group to look in.

string $key

The key to look up.

mixed $data

The data to store.

integer $timeout

how long the data should live in the cache.

lookup_parent_data()

lookup_parent_data(string  $guid) : array|false

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

string $guid

The guid of which a parent is searched.

Returns

array|false —

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

update_parent_data()

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

string $object_guid

The guid of which a parent is saved.

array $parent_data

The guid and classname of the parent which is saved.

_create_backend()

_create_backend(string  $name, array  $config) : \Doctrine\Common\Cache\CacheProvider

Creates an instance of the handler described by the configuration passed to the function.

The configuration array must include the configuration parameters driver and directory, as outlined in the midcom_services_cache_backend class documentation.

All backends will be collected in the $_backends array, indexed by their name.

Any duplicate instantiation will be intercepted, throwing a critical error.

Parameters

string $name

The name of the backend, must be unique throughout the system.

array $config

The configuration of the backend to create. It must contain the key 'driver', which indicates which backend to use.

Returns

\Doctrine\Common\Cache\CacheProvider —

The new backend.

prepare_backend()

prepare_backend(array  $config,   $name) 

Parameters

array $config
$name