It's better when it's simple

User Tools

Site Tools


memcache Plugin

Compatible with DokuWiki


plugin Abstraction wrapper to use persistent memory storage for caching data

Last updated on

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with cache

Needed for explorertree, settingstree


This plugin is an abstraction layer to use a supported persistent memory storage as persistent data cache. The purpose is to supply a unified and portable way to allow plugin authors to use different persistent memory php extensions (e.g. APC / APCu or wincache).

If the environment does not have any supported persistent memory extension, it has a fallback engine that emulates persistent memory (but without the performance boost).

Plugin authors should check if there is real cache, and disable or lighten caching with the fallback cache.


It's recommended have one of the below engines installed and enabled on your system (check your php configuration).

Supported persistent memory engines:

Fallback / emulation engine:

  • fake, which uses the filesystem hence it is only for compatibility.

The plugins should be marked as dependency for plugins which use it to allow automatic installation.

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Some engines may require configuration.


See tips and general info in FAQ.


To use the plugin simply load it, and after this you have multiple ways to use it.

// load plugin:
   $plugin = plugin_load('helper', 'memcache');
// use plugin by instanced object:
   $used_driver = $plugin->driver();
// use plugin as static codes:
   $used_driver = memcache::driver();
// list of usable function:
   $function_list = $plugin->getMethods();

The methods available to utilize the persistent storage have the same name and arguments when used statically or by instanced class.

The wrapper itself is singleton: so once its loaded, it remains available.


The following methods are available:



Returns the backend driver as string (which is either wincache or apc currently or fake if neither is supported, and using the fallback instead).



Returns true if the cache is emulated (i.e. driver is fake).


$loaded_plugin->add(string $key, mixed $val [, int $ttl = 0]);
memcache::add(string $key, mixed $val [, int $ttl = 0]);

Add one arbitary value $val identified by $key to persistent storage, if it does not exists already.
Returns boolean success (false if key already exists or something went wrong).
If $ttl parameter is given and positive, it will set time-to-live (in seconds) after which the value/key is removed. If $ttl is 0 the data will remain in cache until it is deleted or $ttl overridden when later set is used.


$loaded_plugin->set(string $key, mixed $val [, int $ttl = 0]);
memcache::set(string $key, mixed $val [, int $ttl = 0]);

Set one arbitary value $val identified by $key to persistent storage: it's added if not exists or overwrite old value if already exists.
Returns boolean success (false if something went wrong).
If $ttl parameter is given and positive, it will set time-to-live (in seconds) after which the value/key is removed. If $ttl is 0 the data will remain in cache until it is deleted or $ttl overridden when later set is used.


$loaded_plugin->exists(string $key);
memcache::exists(string $key);

Checks if a $key already exists. Returns boolean existence.


$loaded_plugin->del(string $key);
memcache::del(string $key);

Deletes data identified by $key.
Returns boolean success. (i.e. true if data is deleted, and false if data not exists or something went wrong.)


$loaded_plugin->get(string $key [,bool &$success = false] );
memcache::get(string $key [,bool &$success = false]);

Retrieves a value identified by $key, returns retrieved value or null.
The $success out-parameter can be checked to see success (you may have null as stored value: but $success will be true if that is the stored value).



Empties the whole storage, removing every key-value pars regardless of TTL. This is server-wide, so data of every other scripts using the same storage will be purged as well.
Returns success (which is always true).

Configuration and Settings

Plugin configuration options:

  • debug_check_keys : Both apc and wincache supports arrays for many functions, this class DOES NOT. The variables are not checked for better performance, but checking can be enabled for debugging in which case non-string keys trigger error.

Later versions or added engines may add some.

Change Log

  • 2015-06-22
    • Initial release

Known Bugs and Issues

None yet…

ToDo/Wish List

Requests for additional engine support or new features.




plugin/memcache.txt · Last modified: 2022-07-30 00:08 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki