Class QueryCacher

Handles caching queries and loading results from the cache.

Used by Cake\Datasource\QueryTrait internally.

Namespace: Cake\Datasource

Properties summary

  • $_config protected
    string|\Psr\SimpleCache\CacheInterface

    Config for cache engine.

  • $_key protected
    string|\Closure

    The key or function to generate a key.

Method Summary

Method Detail

__construct() public

__construct(mixed $key, mixed $config)

Constructor.

Parameters

string|\Closure $key

The key or function to generate a key.

string|\Psr\SimpleCache\CacheInterface $config

The cache config name or cache engine instance.

Throws

RuntimeException

_resolveCacher() protected

_resolveCacher()

Get the cache engine.

Returns

\Psr\SimpleCache\CacheInterface

_resolveKey() protected

_resolveKey(object $query)

Get/generate the cache key.

Parameters

object $query

The query to generate a key for.

Returns

string

Throws

RuntimeException

fetch() public

fetch(object $query)

Load the cached results from the cache or run the query.

Parameters

object $query

The query the cache read is for.

Returns

mixed|null

Either the cached results or null.

store() public

store(object $query, \Traversable $results)

Store the result set into the cache.

Parameters

object $query

The query the cache read is for.

\Traversable $results

The result set to store.

Returns

bool

True if the data was successfully cached, false on failure

Property Detail

$_config protected

Config for cache engine.

Type

string|\Psr\SimpleCache\CacheInterface

$_key protected

The key or function to generate a key.

Type

string|\Closure

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Datasource.QueryCacher.html