class MemoryCache

Query memory cache class.

Stores query results in memory to avoid running duplicate queries

Adapted from october\rain\database\MemoryCache

Traits

Singleton trait.

Properties

static protected $instance from  Singleton
protected array $cache

Cached results.

protected array $tableMap

The mapper between hashed keys and table names.

protected bool $enabled

Methods

static 
instance()

Create a new instance of this singleton.

static 
forgetInstance()

Forget this singleton's instance if it exists

__construct()

Constructor.

initialize()

Initialize the singleton free from constructor parameters.

__clone()

No description

__wakeup()

No description

bool
enabled($switch = null)

Check if the memory cache is enabled.

bool
has(Builder $query)

Check if the given query is cached.

array|null
get(Builder $query)

Get the cached results for the given query.

void
put(Builder $query, array $results)

Store the results for the given query.

void
forget(string $table)

Delete the cache for the given table.

void
flush()

Clear the memory cache.

string
hash(Builder $query)

Calculate a hash key for the given query.

Details

in Singleton at line 18
final static instance()

Create a new instance of this singleton.

in Singleton at line 28
final static forgetInstance()

Forget this singleton's instance if it exists

in Singleton at line 36
final protected __construct()

Constructor.

in Singleton at line 44
protected initialize()

Initialize the singleton free from constructor parameters.

in Singleton at line 48
__clone()

No description

in Singleton at line 53
__wakeup()

No description

at line 43
bool enabled($switch = null)

Check if the memory cache is enabled.

Parameters

$switch

Return Value

bool

at line 58
bool has(Builder $query)

Check if the given query is cached.

Parameters

Builder $query

Return Value

bool

at line 69
array|null get(Builder $query)

Get the cached results for the given query.

Parameters

Builder $query

Return Value

array|null

at line 85
void put(Builder $query, array $results)

Store the results for the given query.

Parameters

Builder $query
array $results

Return Value

void

at line 104
void forget(string $table)

Delete the cache for the given table.

Parameters

string $table

Return Value

void

at line 121
void flush()

Clear the memory cache.

Return Value

void

at line 133
protected string hash(Builder $query)

Calculate a hash key for the given query.

Parameters

Builder $query

Return Value

string