CRM_Utils_Cache
class CRM_Utils_Cache
Cache is an empty base object, we'll modify the scheme when we have different caching schemes
Constants
DELIMITER |
|
Properties
static object | $_singleton | (Quasi-Private) Treat this as private. It is marked public to facilitate testing. |
Methods
Constructor.
Singleton function used to manage this object.
Get cache relevant settings.
Create a new, named, limited-use cache.
Normalize a cache key.
Assert that a key is well-formed.
No description
Generate a unique negative-acknowledgement token (NACK).
Details
at line 59
CRM_Utils_Cache
__construct(array $config)
Constructor.
at line 68
static CRM_Utils_Cache_Interface
singleton()
Singleton function used to manage this object.
at line 88
static array
getCacheSettings($cachePlugin)
Get cache relevant settings.
at line 182
static CRM_Utils_Cache_Interface
create(array $params = [])
Create a new, named, limited-use cache.
This is a factory function. Generally, you should use Civi::cache($name) to locate managed cached instance.
at line 235
static string
cleanKey(string $key)
Normalize a cache key.
This bridges an impedance mismatch between our traditional caching and PSR-16 -- PSR-16 accepts a narrower range of cache keys.
at line 262
static string
assertValidKey(string $key)
Assert that a key is well-formed.
at line 284
static string
getCacheDriver()
at line 327
static string
nack()
Generate a unique negative-acknowledgement token (NACK).
When using PSR-16 to read a value, the $cahce->get()
will a return a default
value on cache-miss, so it's hard to know if you've gotten a geniune value
from the cache or just a default. If you're in an edge-case where it matters
(and you want to do has()+get() in a single roundtrip), use the nack() as
the default:
$nack = CRM_Utils_Cache::nack(); $value = $cache->get('foo', $nack); echo ($value === $nack) ? "Cache has a value, and we got it" : "Cache has no value".
The value should be unique to avoid accidental matches.