Cacheable
Add caching capabilities to any class.
Table of Contents
Properties
- $cachePrefix : string
- The cache prefix to use for caching.
- $cacheTtl : int
- The cache ttl to use for caching.
- $cacheInstance : PioniaCache|null
- The cache instance to use for caching.
Methods
- cache() : bool|mixed
- Caches the value if the value is not null.
- ClearByKeys() : bool
- Clear the cache.
- deleteCache() : bool
- Delete the cache for the key.
- getCache() : mixed
- getCacheInstance() : PioniaCache|null
- hasCache() : bool
- Check if the cache has the key.
- setCache() : bool
- setCacheInstance() : void
- Set the cache instance to use for caching.
- updateCache() : void
- cleanCacheKey() : string
- getKeyName() : string
- Converts the key to snake case and appends the current class prefix if it does not exist.
- logger() : LoggerInterface|null
Properties
$cachePrefix
The cache prefix to use for caching.
public
string
$cachePrefix
= __CLASS__
$cacheTtl
The cache ttl to use for caching.
public
int
$cacheTtl
= 60
Defaults to 60 seconds.
$cacheInstance
The cache instance to use for caching.
private
PioniaCache|null
$cacheInstance
= null
Methods
cache()
Caches the value if the value is not null.
public
cache(string $key[, mixed $value = null ][, mixed $ttl = null ][, bool|null $exact = false ]) : bool|mixed
Parameters
- $key : string
-
The key to cache
- $value : mixed = null
-
The value to cache
- $ttl : mixed = null
-
The time to live for the cache
- $exact : bool|null = false
-
If passed, the key won't be parsed at all, it will be cached as is.
Return values
bool|mixedClearByKeys()
Clear the cache.
public
ClearByKeys(array<string|int, mixed> $keys[, bool|null $exact = false ]) : bool
Parameters
- $keys : array<string|int, mixed>
-
The keys to clear
- $exact : bool|null = false
-
If passed, the keys won't be parsed at all
Return values
booldeleteCache()
Delete the cache for the key.
public
deleteCache(string $key[, bool $exact = false ]) : bool
Parameters
- $key : string
-
The key to delete
- $exact : bool = false
-
If passed, the key won't be parsed at all
Return values
boolgetCache()
public
getCache( $key[, bool|null $exact = false ]) : mixed
Parameters
getCacheInstance()
public
getCacheInstance() : PioniaCache|null
Return values
PioniaCache|nullhasCache()
Check if the cache has the key.
public
hasCache( $key[, bool|null $exact = false ]) : bool
Will not throw an exception if the key is not set or the cache is not activated.
Parameters
Return values
boolsetCache()
public
setCache(string $key, mixed $value[, mixed $ttl = null ][, bool|null $exact = false ]) : bool
Parameters
- $key : string
- $value : mixed
- $ttl : mixed = null
- $exact : bool|null = false
Return values
boolsetCacheInstance()
Set the cache instance to use for caching.
public
setCacheInstance(PioniaCache|null $cache) : void
Parameters
- $cache : PioniaCache|null
updateCache()
public
updateCache(mixed $key, mixed $newValue[, mixed $exact = false ][, int|null $ttl = null ]) : void
Parameters
- $key : mixed
- $newValue : mixed
- $exact : mixed = false
- $ttl : int|null = null
cleanCacheKey()
private
cleanCacheKey(string $key) : string
Parameters
- $key : string
Return values
stringgetKeyName()
Converts the key to snake case and appends the current class prefix if it does not exist.
private
getKeyName(string $key) : string
Parameters
- $key : string
Return values
stringlogger()
private
logger() : LoggerInterface|null