phalcon/cphalcon · error · Phalcon\Mvc\Model\Query\Exceptions\MissingCacheKey

A cache key must be provided to identify the cached…

Error message

A cache key must be provided to identify the cached resultset in the cache backend

What it means

Query::execute() found a valid cacheOptions array but no 'key' element, so the cached resultset cannot be identified in the backend; MissingCacheKey is thrown. The missing input is the required 'key' entry of the cache options array.

Solutions

  1. Add a 'key' element to the cache options array
  2. Use a stable, unique key per query (include bind params if they vary)
  3. Remove caching if the query should always hit the database

Example fix

->cache(['key' => 'robots-list-' . $type, 'lifetime' => 3600])
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Thrown at phalcon/Mvc/Model/Query.zep:350 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/38aadfe6e24f7ce7. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Mvc/Model/Query.zep:350

    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();
            }

            /**
             * If the lifetime is different than the cache lifetime, assign
             * the cache lifetime to the current cache setting
             */
            let adapter       = cache->getAdapter();
            let cacheLifetime = adapter->getLifetime();

View on GitHub (pinned to b7419de9cd)