cache
in package
Main cache handling class implementing a flexible caching system
Provides a facade for different cache backends (File, Redis, MariaDB) with consistent interface
Tags
Table of Contents
Properties
- $_engine : string|null
- $key : string
- $lifetime : int
- $timestamp : int
- $value : mixed|null
Methods
- byKey() : cache
- Get cache entry by key
- clean() : void
- Clean expired entries and perform maintenance
- delete() : void
- Delete a cache entry
- exist() : bool
- Check if a cache entry exists and is valid
- flush() : mixed
- Delete all cache entries
- getDatetime() : string
- Get cache entry datetime
- getEngine() : string
- Get current cache engine class name
- getKey() : string
- Get cache entry key
- getLifetime() : int
- Get cache entry lifetime
- getTimestamp() : int
- Get cache entry timestamp
- getValue() : mixed
- Get cache entry value
- isPersistOk() : bool
- Check if persistence is working correctly
- persist() : void
- Persist cache to storage if supported by engine
- remove() : mixed
- Remove current cache entry
- restore() : void
- Restore cache from persistence if supported by engine
- save() : mixed
- Save current cache entry
- set() : mixed
- Set a cache entry
- setDatetime() : self
- Set cache entry datetime
- setKey() : self
- Set cache entry key
- setLifetime() : self
- Set cache entry lifetime
- setTimestamp() : self
- Set cache entry timestamp
- setValue() : self
- Set cache entry value
Properties
$_engine
private
static string|null
$_engine
= \null
Current cache engine class name
$key
private
string
$key
Cache entry key
$lifetime
private
int
$lifetime
= 0
Cache lifetime in seconds (0 for infinite)
$timestamp
private
int
$timestamp
Unix timestamp of cache entry creation
$value
private
mixed|null
$value
= \null
Cache entry value
Methods
byKey()
Get cache entry by key
public
static byKey(string $_key) : cache
Parameters
- $_key : string
-
Cache key
Return values
cache —Always returns a cache object (value will be null if not found)
clean()
Clean expired entries and perform maintenance
public
static clean() : void
delete()
Delete a cache entry
public
static delete(string $_key) : void
Parameters
- $_key : string
-
Cache key to delete
exist()
Check if a cache entry exists and is valid
public
static exist(string $_key) : bool
Parameters
- $_key : string
-
Cache key
Return values
bool —True if cache exists and is valid
flush()
Delete all cache entries
public
static flush() : mixed
Return values
mixed —Result depends on cache engine implementation
getDatetime()
Get cache entry datetime
public
getDatetime() : string
Return values
string —Datetime in Y-m-d H:i:s format
getEngine()
Get current cache engine class name
public
static getEngine() : string
Return values
string —Cache engine class name ('FileCache', 'RedisCache', or 'MariadbCache')
getKey()
Get cache entry key
public
getKey() : string
Return values
string —Cache key
getLifetime()
Get cache entry lifetime
public
getLifetime() : int
Return values
int —Lifetime in seconds
getTimestamp()
Get cache entry timestamp
public
getTimestamp() : int
Return values
int —Unix timestamp
getValue()
Get cache entry value
public
getValue([mixed $_default = '' ]) : mixed
Parameters
- $_default : mixed = ''
-
Default value if cache is empty
Return values
mixed —Cached value or default
isPersistOk()
Check if persistence is working correctly
public
static isPersistOk() : bool
Return values
bool —True if persistence is working
persist()
Persist cache to storage if supported by engine
public
static persist() : void
remove()
Remove current cache entry
public
remove() : mixed
Return values
mixed —Result depends on cache engine implementation
restore()
Restore cache from persistence if supported by engine
public
static restore() : void
save()
Save current cache entry
public
save() : mixed
Return values
mixed —Result depends on cache engine implementation
set()
Set a cache entry
public
static set(string $_key, mixed $_value[, int $_lifetime = 0 ]) : mixed
Parameters
- $_key : string
-
Cache key
- $_value : mixed
-
Value to cache
- $_lifetime : int = 0
-
Cache lifetime in seconds (0 for infinite)
Return values
mixed —Result depends on cache engine implementation
setDatetime()
Set cache entry datetime
public
setDatetime(string $_datetime) : self
Parameters
- $_datetime : string
-
Datetime in Y-m-d H:i:s format
Return values
selfsetKey()
Set cache entry key
public
setKey(string $_key) : self
Parameters
- $_key : string
-
Cache key
Return values
selfsetLifetime()
Set cache entry lifetime
public
setLifetime(int $_lifetime) : self
Parameters
- $_lifetime : int
-
Lifetime in seconds
Return values
selfsetTimestamp()
Set cache entry timestamp
public
setTimestamp(int $_timestamp) : self
Parameters
- $_timestamp : int
-
Unix timestamp
Return values
selfsetValue()
Set cache entry value
public
setValue(mixed $_value) : self
Parameters
- $_value : mixed
-
Value to cache