phalcon/cphalcon · error · Phalcon\Mvc\Model\Query\Exceptions\InvalidCachingOptions
Invalid caching options
Error message
Invalid caching options
What it means
Query::execute() reads cacheOptions set via cache(); if the stored value is not an array (e.g. true or a string) InvalidCachingOptions is thrown. The faulty input is the argument passed to Phalcon\Mvc\Model::query()->cache(...) — it must be an array of options.
Solutions
- Pass an array to cache(), e.g. ['key' => 'my-key', 'lifetime' => 3600]
- Remove the cache() call if caching is not intended
- Check wrappers that forward cache options for type loss
Example fix
$robots = Robots::query(['key' => 'robots-all', 'lifetime' => 86400])->execute();
Defensive patterns
Strategy: type-guard
Prevention
- Centralize cache option construction in a helper with array type validation
- Use IDE types/static analysis to catch non-array arguments
When it happens
Trigger: Thrown at phalcon/Mvc/Model/Query.zep:343 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/36769f8448b8ce29.
Report an issue: GitHub.
Appendix: source
Thrown at phalcon/Mvc/Model/Query.zep:343
}
/**
* Executes a parsed PHQL statement
*
* @return mixed
*/
public function execute(array bindParams = [], array bindTypes = [])
{
var adapter, cache, cacheLifetime, cacheOptions, cacheService,
defaultBindParams, defaultBindTypes, intermediate, key, lifetime,
mergedParams, mergedTypes, preparedResult, result, type, uniqueRow;
let uniqueRow = this->uniqueRow,
cacheOptions = this->cacheOptions;
if cacheOptions !== null {
if unlikely typeof cacheOptions != "array" {
throw new InvalidCachingOptions();
}
/**
* The user must set a cache key
*/
if unlikely !fetch key, cacheOptions["key"] {
throw new MissingCacheKey();
}
if !fetch cacheService, cacheOptions["service"] {
let cacheService = "modelsCache";
}
let cache = this->container->getShared(cacheService);
if unlikely (true !== is_a(cache, CacheInterface::class)) {
throw new InvalidQueryCacheService();
}View on GitHub (pinned to b7419de9cd)