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.
Common
Advanced
Name | Return | Summary | |
---|---|---|---|
$cache->getInfo() $cache->getInfo() $cache->getInfo(bool $verbose = true, $names = [], $exclude = [], array $cols = []) | array | Get information about all the caches in this WireCache | |
$cache->maintenance() $cache->maintenance() $cache->maintenance($obj = null) | bool | Cache maintenance removes expired caches | |
$cache->preload() $cache->preload(array $names) $cache->preload(array $names, $expire = null) | (nothing) | Preload the given caches, so that they will be returned without query on the next get() call | |
$cache->preloadFor() $cache->preloadFor($ns) $cache->preloadFor($ns, $expire = null) | (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.
Name | Return | Summary | |
---|---|---|---|
WireCache::defaultCacheClass const | WireCacheDatabase | Default cache class | |
WireCache::expireDaily const | 86400 | Cache should expire once per day | |
WireCache::expireHourly const | 3600 | Cache should expire once per hour | |
WireCache::expireIgnore const | false | Ignore expiration (skips expiration check) 3.0.218+ | |
WireCache::expireMonthly const | 2419200 | Cache should expire once per month | |
WireCache::expireNever const | 2010-04-08 03:10:10 | Cache should never expire (unless manually cleared). | |
WireCache::expireNow const | 0 | Cache should expire now | |
WireCache::expireReserved const | 2010-04-08 03:10:01 | Cache 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 const | 2010-01-01 01:01:01 | Cache should expire when a given resource (Page or Template) is saved. | |
WireCache::expireWeekly const | 604800 | Cache 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.236