phalcon/cphalcon · error · Phalcon\Mvc\Model\Query\Exceptions\ResultsetNonCacheable
Only PHQL statements that return resultsets can be cached
Error message
Only PHQL statements that return resultsets can be cached
What it means
After executing, Query::execute() only caches results when cacheOptions are set, and it requires statement type PHQL_T_SELECT; caching an INSERT/UPDATE/DELETE result raises ResultsetNonCacheable. The faulty input is a cache() configuration applied to a non-SELECT PHQL statement.
Solutions
- Only attach cache() to SELECT queries
- Remove the cache() call from insert/update/delete queries
- Conditionally apply cache options only for read paths
Example fix
if ($isReadQuery) { $builder->cache(['key' => $cacheKey]); } Defensive patterns
Strategy: validation
Prevention
- Encapsulate caching in repository read methods only
- Invalidate related cache keys on writes instead of caching writes
When it happens
Trigger: Thrown at phalcon/Mvc/Model/Query.zep:475 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/be07d4d405d1f39d.
Report an issue: GitHub.
Appendix: source
Thrown at phalcon/Mvc/Model/Query.zep:475
mergedParams,
mergedTypes
);
break;
default:
throw new UnknownPhqlStatement(type);
}
/**
* We store the resultset in the cache if any
*/
if cacheOptions !== null {
/**
* Only PHQL SELECTs can be cached
*/
if type != PHQL_T_SELECT {
throw new ResultsetNonCacheable();
}
cache->set(key, result, lifetime);
}
/**
* Check if only the first row must be returned
*/
if uniqueRow {
let preparedResult = result->getFirst();
} else {
let preparedResult = result;
}
return preparedResult;
}
/**View on GitHub (pinned to b7419de9cd)