$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.137

Twitter updates

  • ProcessWire 3.0.146 on the dev branch contains about 22 commits with a combination of useful upgrades and issue report resolutions, more details in this forum post: More
    22 November 2019
  • ProcessWire 3.0.144 and 3.0.145 add improved field template context override settings and include a new Inputfields API, along with numerous other issue fixes, optimizations and improvements to the core. More
    8 November 2019
  • ProcessWire 3.0.144 core updates: Upgraded overrides section in the field editor, a new Inputfields JS API, and more— More
    1 November 2019

Latest news

  • ProcessWire Weekly #291
    In the 291st issue of ProcessWire Weekly we're going to take a closer look at the latest core updates, check out a brand new third party module called ProcessHelpVideos, and introduce a new site of the week. Read on!
    Weekly.pw / 8 December 2019
  • New User Activity module
    Blog / 29 November 2019
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer