WireDataDB::getCache()

Get and/or set cached value

Sets value from callable function and caches it so that later calls do not call the callable function again until it expires.

Available since version 3.0.258.

Example

// returns same random number for 1 hour (3600 seconds)
echo $page->meta->getCache('my_rand_num', 3600, function() {
  return mt_rand();
}); 

Usage

$array = $wireDataDB->getCache(string $key, int $maxAge, callable $func);

Arguments

NameType(s)Description
$keystring

Name of property to get or set

$maxAgeint

Maximum age in seconds

$funccallable

Function that returns the value when creating (when new or after expiration)

Return value

array mixed null


WireDataDB methods and properties

API reference based on ProcessWire core version 3.0.257