QueryKeyHelper
in package
Builds query cache keys and key patterns.
A query key is query:ServiceClass:method:paramsHash. The query: prefix is part of the
key returned here, so the cache class adds nothing.
Table of Contents
Constants
- PREFIX : mixed = 'query:'
- DATETIME_BUCKET_SECONDS : mixed = 300
- Time granularity of dates in a cache key, in seconds. Equals the default query cache TTL; a finer granularity would only create keys for "now" filters that nobody reads again.
Methods
- generate() : string
- Generates the complete query cache key including the prefix.
- generateMethodPattern() : string
- Returns the pattern that deletes the query cache entries of one method.
- generatePattern() : string
- Returns the pattern that deletes all query cache entries of one service.
- hash() : string
- Returns a deterministic hash of the query parameters including the includes.
- isQueryKey() : bool
- Returns whether the key is a query cache key.
- parseKey() : array{prefix: string, className: string, methodName: string, hash: string}|null
- Extracts the parts of a query key; returns null when the key is malformed.
- isAssociative() : bool
- Returns whether the array is associative.
- normalizeValue() : mixed
- Normalizes a value for consistent hashing.
Constants
PREFIX
public
mixed
PREFIX
= 'query:'
DATETIME_BUCKET_SECONDS
Time granularity of dates in a cache key, in seconds. Equals the default query cache TTL; a finer granularity would only create keys for "now" filters that nobody reads again.
private
mixed
DATETIME_BUCKET_SECONDS
= 300
Methods
generate()
Generates the complete query cache key including the prefix.
public
static generate(string $className, string $methodName, array<string, mixed> $params) : string
Format: query:ServiceClass:methodName:sha256hash.
Parameters
- $className : string
-
service class name
- $methodName : string
-
method name (
findAll,findBy, ...) - $params : array<string, mixed>
-
query parameters (filters, order, limit, offset)
Return values
string —complete cache key
generateMethodPattern()
Returns the pattern that deletes the query cache entries of one method.
public
static generateMethodPattern(string $className, string $methodName) : string
Format: query:ServiceClass:methodName:*.
Parameters
- $className : string
-
service class name
- $methodName : string
-
method name
Return values
string —pattern for the Redis key scan
generatePattern()
Returns the pattern that deletes all query cache entries of one service.
public
static generatePattern(string $className) : string
Format: query:ServiceClass:*.
Parameters
- $className : string
-
service class name
Return values
string —pattern for the Redis key scan
hash()
Returns a deterministic hash of the query parameters including the includes.
public
static hash(array<string, mixed> $params, string|array<int, mixed> $includes) : string
The payload depends on the include set, so a different include set yields a different
key. Throws on a Closure in a filter (via normalizeValue()), which would otherwise
silently collide. The wire-payload key is built by
QueryCacheKeyFactory.
Parameters
- $params : array<string, mixed>
-
filters, order, limit, offset (and
computeTotalCount) - $includes : string|array<int, mixed>
-
relations to load (dotted paths)
Return values
stringisQueryKey()
Returns whether the key is a query cache key.
public
static isQueryKey(string $key) : bool
Parameters
- $key : string
Return values
boolparseKey()
Extracts the parts of a query key; returns null when the key is malformed.
public
static parseKey(string $queryKey) : array{prefix: string, className: string, methodName: string, hash: string}|null
Parameters
- $queryKey : string
-
query cache key
Return values
array{prefix: string, className: string, methodName: string, hash: string}|nullisAssociative()
Returns whether the array is associative.
private
static isAssociative(array<string|int, mixed> $array) : bool
Parameters
- $array : array<string|int, mixed>
Return values
boolnormalizeValue()
Normalizes a value for consistent hashing.
private
static normalizeValue(mixed $value) : mixed
Parameters
- $value : mixed