MemoryCache
in package
Uses
Singleton
Query memory cache class.
Stores query results in memory to avoid running duplicate queries
Tags
Table of Contents
- $cache : array<string|int, mixed>
- Cached results.
- $enabled : bool
- $instance : mixed
- $tableMap : array<string|int, mixed>
- The mapper between hashed keys and table names.
- __clone() : mixed
- __wakeup() : mixed
- enabled() : bool
- Check if the memory cache is enabled.
- flush() : void
- Clear the memory cache.
- forget() : void
- Delete the cache for the given table.
- forgetInstance() : mixed
- Forget this singleton's instance if it exists
- get() : array<string|int, mixed>|null
- Get the cached results for the given query.
- has() : bool
- Check if the given query is cached.
- instance() : mixed
- Create a new instance of this singleton.
- put() : void
- Store the results for the given query.
- __construct() : mixed
- Constructor.
- hash() : string
- Calculate a hash key for the given query.
- init() : mixed
- Initialize the singleton free from constructor parameters.
Properties
$cache
Cached results.
protected
array<string|int, mixed>
$cache
= []
$enabled
protected
bool
$enabled
= true
Store enabled state.
$instance
protected
static mixed
$instance
$tableMap
The mapper between hashed keys and table names.
protected
array<string|int, mixed>
$tableMap
= []
Methods
__clone()
public
__clone() : mixed
Return values
mixed —__wakeup()
public
__wakeup() : mixed
Return values
mixed —enabled()
Check if the memory cache is enabled.
public
enabled([mixed $switch = null ]) : bool
Parameters
- $switch : mixed = null
Return values
bool —flush()
Clear the memory cache.
public
flush() : void
Return values
void —forget()
Delete the cache for the given table.
public
forget(string $table) : void
Parameters
- $table : string
Return values
void —forgetInstance()
Forget this singleton's instance if it exists
public
final static forgetInstance() : mixed
Return values
mixed —get()
Get the cached results for the given query.
public
get(QueryBuilder $query) : array<string|int, mixed>|null
Parameters
- $query : QueryBuilder
Return values
array<string|int, mixed>|null —has()
Check if the given query is cached.
public
has(QueryBuilder $query) : bool
Parameters
- $query : QueryBuilder
Return values
bool —instance()
Create a new instance of this singleton.
public
final static instance() : mixed
Return values
mixed —put()
Store the results for the given query.
public
put(QueryBuilder $query, array<string|int, mixed> $results) : void
Parameters
- $query : QueryBuilder
- $results : array<string|int, mixed>
Return values
void —__construct()
Constructor.
protected
final __construct() : mixed
Return values
mixed —hash()
Calculate a hash key for the given query.
protected
hash(QueryBuilder $query) : string
Parameters
- $query : QueryBuilder
Return values
string —init()
Initialize the singleton free from constructor parameters.
protected
init() : mixed