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

Cache service must be an object implementing…

Error message

Cache service must be an object implementing Phalcon\Cache\CacheInterface

What it means

Query::execute() resolves the service named in cacheOptions['service'] (default 'modelsCache') from the DI container and verifies it implements Phalcon\Cache\CacheInterface; otherwise this error is thrown. The faulty input is a misconfigured or missing cache service in the DI container.

Solutions

  1. Register a 'modelsCache' service returning a Phalcon\Cache\CacheInterface adapter
  2. Point cacheOptions['service'] to an existing, correctly typed service name
  3. Upgrade legacy cache services to the CacheInterface implementation

Example fix

$di->setShared('modelsCache', function () { return new Cache(new Libmemcached(new LibmemcachedOptions())); });
Defensive patterns

Strategy: type-guard

Prevention

When it happens

Trigger: Thrown at phalcon/Mvc/Model/Query.zep:360 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/8cd02596cc6538f3. Report an issue: GitHub.

Appendix: source

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

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

            if !fetch lifetime, cacheOptions["lifetime"] {
                let lifetime = cacheLifetime;
            }

            let result = false;
            if (cache->has(key)) {
                let result = cache->get(key);
            }

View on GitHub (pinned to b7419de9cd)