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

Twitter updates

  • New post: Quietly and without interruption this week, the ProcessWire.com website (and all subdomains) moved from a single static server to a load-balanced multi-server environment, giving us even more horsepower and redundancy than before— More
    19 April 2019
  • New post: With ProcessWire 3.0.130, this week we’ll take a detailed look at a few useful new API additions made in the last few weeks, along with examples of each—More
    12 April 2019
  • New post: This week ProcessWire ProMailer has been released, plus we’ve got a nice upgrade in our community support forum, and more— More
    15 March 2019

Latest news

  • ProcessWire Weekly #258
    In the 258th issue of ProcessWire Weekly we'll cover a hosting upgrade for the processwire.com site and it's subdomains, introduce PW Review and Terminal module, and feature the new site of O'Neil Cinema. Read on!
    Weekly.pw / 20 April 2019
  • ProcessWire.com website hosting upgrades
    Quietly and without interruption this week, our whole website moved from a single static server to a load-balanced multi-server environment, giving us even more horsepower and redundancy than before.
    Blog / 19 April 2019
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.