rah_memcached
A plugin for Textpattern CMS that stores parts of your templates in Memcached, a distributed in-memory key-value caching system.
Install
Using Composer:
$ composer require rah/rah_memcached
Basics
The plugin, rah_memcached, introduces a new container tag to Textpattern’s arsenal. The tag stores the wrapped content, and variables set within it, in Memcached’s in-memory storage.
<rah::memcached>
<txp:variable name="variable1" value="value" />
<txp:article_custom limit="200">
<txp:title />
</txp:article_custom>
</rah::memcached>
On subsequent calls the resulting output markup and variables will be loaded from memory, skipping template parsing and code execution, speeding up your site and alleviating database load.
Requirements
- Textpattern 4.7.0 or newer.
- PHP 7.1.0 or newer.
- Memcached PHP extension.
- libmemcached client library.
- Memcached server.
Install external dependencies
To use the plugin you must first install Memcached, libmemcached and the PHP Memcached extension.
On Ubuntu and Debian
Using apt:
$ apt install memcached php5-memcached
On Mac OS
$ brew install pkg-config php libmemcached memcached
$ pecl install memcached
Configuration
Connected server can be configured through Textpattern’s config.php
:
define('\RAH_MEMCACHED_HOST', 'localhost');
define('\RAH_MEMCACHED_PORT', 11211);
Attributes
<rah::memcached>
...contained statement...
</rah::memcached>
The tag is a container and attributes for it follow.
expires
Time in seconds it takes to the stored item to expire and be refreshed. If zero (0
), the cache is kept in memory until the cache is flushed or Memcached is restarted.
Default: 0
Example: expires="3600"
persist
If enabled, ignores content updates as set by site’s lastmod
timestamp.
Default: disabled Example: persist
name
Sets a name, a key, for the cached item. The given name used identify the item and fetch it from the storage. If a name is not defined, its automatically created by hashing the given contained markup. While the name is option, giving it is more efficient and avoids any potential collisions.
Default: undefined Example: name="mykey"
Examples
Store section navigation in memory
<rah::memcached name="navigation">
<txp:section_list wraptag="ul" break="li">
<txp:section />
</txp:section_list>
</rah::memcached>
Store variables in memory
<rah::memcached> <txp:variable name="color" value="red" /> <txp:variable name="size" value="small" /> </rah::memcached>
Color: <txp:variable name="color" /> Size: <txp:variable name="size" />
Changelog
Version 0.2.0 – upcoming
- Register the tag.
- Replaced
lastmod
attribute withpersist
. - Now requires Textpattern 4.7.0 or newer.
Version 0.1.0 – 2014/03/19
- Initial release.