W3cubDocs

/CakePHP 4.4

Class QueryCacher

Handles caching queries and loading results from the cache.

Used by {@link \Cake\Datasource\QueryTrait} internally.

Namespace: Cake\Datasource
See: \Cake\Datasource\QueryTrait::cache() for the public interface.

Property Summary

  • $_config protected
    Psr\SimpleCache\CacheInterface|string

    Config for cache engine.

  • $_key protected
    Closure|string

    The key or function to generate a key.

Method Summary

Method Detail

__construct() public

__construct(Closure|string $key, Psr\SimpleCache\CacheInterface|string $config)

Constructor.

Parameters

Closure|string $key

The key or function to generate a key.

Psr\SimpleCache\CacheInterface|string $config

The cache config name or cache engine instance.

Throws

RuntimeException

_resolveCacher() protected

_resolveCacher(): Psr\SimpleCache\CacheInterface

Get the cache engine.

Returns

Psr\SimpleCache\CacheInterface

_resolveKey() protected

_resolveKey(object $query): string

Get/generate the cache key.

Parameters

object $query

The query to generate a key for.

Returns

string

Throws

RuntimeException

fetch() public

fetch(object $query): mixed|null

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

Parameters

object $query

The query the cache read is for.

Returns

mixed|null

store() public

store(object $query, Traversable $results): bool

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

Property Detail

$_config protected

Config for cache engine.

Type

Psr\SimpleCache\CacheInterface|string

$_key protected

The key or function to generate a key.

Type

Closure|string

© 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.4/class-Cake.Datasource.QueryCacher.html