Simple interface to Redis in-memory storage similar to WireCache


ProcessWire interface to Redis memory cache


This module provides a simple interface to the phpredis library for caching contents in-memory. The functionality leans on ProcessWire's WireCache core library.


Compatible with ProcessWire 3.x


Alpha, WiP, use with care


The phpredis extension must be installed.



After installation, you need to enable the module in the module settings by ticking the "Active" checkbox. The server and port are preset to and 6379.

The configuration options support connecting via unix domain sockets and using TLS. You can optionally enable authentication.


CacheRedis registers itself as a PW API variable with the name "redis", so you can access in all the usual ways:

$var = $redis->get('mykey');
$var = wire('redis')->get('otherkey');
$var = $this->redis->get('thirdkey'); // only within Wire derived classes


$redis->fetch($name, $expire, $func)

Retrieve a value from the cache by the given name. If $func is given and no cached entry was found, call $func and use its return value instead, saving that in the cache with the given expiry time.

Alternatively, you can pass an array of names to the method. In that case, an associative array of names and values is returned, with only those keys present that were found in the cache. If you do that, you must not pass a $func parameter.

$redis->store($name, $expire, $value)

Save the value in the cache with the given name as the key and the specified expire time. If $expire is not set, CacheRedis::expireDaily is assumed (24h).


Deletes the entry with the given key name from the cache.


Delete all entries from the cache.

$redis->renderFile($filename, $expire, array $options)

This method behaves similar to $files->render() and actually delegates the file rendering to that method (when creating the cache). The important difference is that this method caches the output according to the given expiry value, rather than re-rendering the file on every call.

If there are any changes to the source file $filename the cache will be automatically re-created, regardless of what is specified for the $expire argument.

// render primary nav from site/templates/partials/primary-nav.php
// and cache for 3600 seconds (1 hour)
echo $redis->renderFile('partials/primary-nav.php', 3600);

Parameters for renderFile:

  • string $filename

    • Filename to render (typically PHP file)
    • Can be full path/file, or dir/file relative to current work directory (which is typically /site/templates/).
      • If providing a file relative to current dir, it should not start with "/".
      • File must be somewhere within site/templates/, site/modules/ or wire/modules/, or provide your own allowedPaths option.
      • Please note that $filename receives API variables already (you don’t have to provide them).

  • int|string $expire

    • Specify one of the CacheRedis::expire* constants.
    • Specify the time in seconds until expiry, up to 30 days.
    • Specify the future date you want it to expire (any value above 2592000 will be treated as a unix timestamp).
    • Specify CacheRedis::expireNever to prevent expiration.
    • Specify CacheRedis::expireSave to expire when any page or template is saved.
    • Specify a selector string. In that case, whenever a page is saved that matches the selector, the cache for the file is cleared.
    • You can specify multiple selectors as an array. This can make sense with multiple selectors and/or if you want to specify selector expiry and a maximum lifetime.
    • Omit for default value, which is CacheRedis::expireDaily.

  • array $options Accepts all options for the WireFileTools::render() method, plus these additional ones:

    • name (string): Optionally specify a unique name for this cache, otherwise $filename will be used as the unique name. (default='')
    • vars (array): Optional associative array of extra variables to send to template file. (default=[])
    • allowedPaths (array): Array of paths that are allowed (default is anywhere within templates, core modules and site modules)
    • throwExceptions (bool): Throw exceptions when fatal error occurs? (default=true)


string|bool Rendered template file or boolean false on fatal error (and throwExceptions disabled)


Licensed under Mozilla Public License v2. See file LICENSE in the repository for details.


Ryan Cramer, creator of ProcessWire. Quite a bit of his well thought out code was taken more or less literally from his WireCache class to keep things compatible and keep from reinventing the wheel.

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Twitter updates

  • ProcessWire 3.0.210 new main/master version released— More
    6 January 2023
  • ProcessWire 3.0.209: Core updates and an interesting AI that knows ProcessWire– More
    30 December 2022
  • Implementing and using TinyMCE 6 in ProcessWire– More
    16 December 2022

Latest news

  • ProcessWire Weekly #454
    In the 454th issue of ProcessWire Weekly we'll introduce a couple of brand new third party modules, check out what's new in the latest dev version of ProcessWire (3.0.211), and more. Read on! / 21 January 2023
  • ProcessWire 3.0.210 new main/master version
    140 commits, 55 resolved issues, dozens of new features, eight contributors, and five new pull requests make yet another great new version of ProcessWire.
    Blog / 6 January 2023
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH