$cache API variable / WireCache class

Provides easy, persistent caching of markup, strings, arrays or PageArray objects.

// Get a cache named 'foo' that lasts for 1 hour (aka 3600 seconds)
$value = $cache->get('foo', 3600, function() {
  // this is called if cache expired or does not exist,
  // so generate a new cache value here and return it
  return "This is the cached value";
});

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireCache class also inherits all the methods and properties of: Wire.

Show $var?             Show args?        

Advanced

NameReturnSummary 
$cache->getInfo()
arrayGet information about all the caches in this WireCache 
$cache->maintenance()
boolCache maintenance removes expired caches 
$cache->preload(array $names)
(nothing)Preload the given caches, so that they will be returned without query on the next get() call 
$cache->preloadFor($ns)
(nothing)Preload all caches for the given object or namespace 

Constants

These constants are used for the $expire argument of get() and save() cache methods.

NameReturnSummary 
WireCache::expireDaily const86400Cache should expire once per day 
WireCache::expireHourly const3600Cache should expire once per hour 
WireCache::expireMonthly const2419200Cache should expire once per month 
WireCache::expireNever const2010-04-08 03:10:10Cache should never expire (unless manually cleared). 
WireCache::expireNow const0Cache should expire now 
WireCache::expireReserved const2010-04-08 03:10:01Cache should never expire and should not be deleted during deleteAll() calls (for PW internal system use) Can only be deleted by delete() calls that specify it directly or match it specifically with a wildcard. 
WireCache::expireSave const2010-01-01 01:01:01Cache should expire when a given resource (Page or Template) is saved. 
WireCache::expireWeekly const604800Cache should expire once per week 

Additional methods and properties

In addition to the methods and properties above, WireCache also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.133

Twitter updates

  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019
  • New post: This week we’ll take a look at 3 different WEBP image strategies that you can use in ProcessWire 3.0.132+. Then we’ll dive into a major update for the Google Client API module, and finish up by outlining some useful new updates in FormBuilder— More
    31 May 2019
  • New post: This week we've added WEBP support in ProcessWire thanks to a GitHub pull request from Horst Nogajski. This enables you to have highly optimized image output in PW and I think you’ll really like the difference it makes— More
    24 May 2019

Latest news

  • ProcessWire Weekly #267
    In the 267th issue of ProcessWire Weekly we're going to cover the latest changes in the development branch of ProcessWire, introduce a new module called MarkupMenu, and highlight a brand new site of the week. Read on!
    Weekly.pw / 22 June 2019
  • ProcessWire 3.0.133 core updates
    ProcessWire 3.0.133 adds a useful new $page->meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type. Read on for all the details, examples and screenshots.
    Blog / 14 June 2019
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK