{"record":{"id":"8cd02596cc6538f3","repo":"phalcon/cphalcon","slug":"cache-service-must-be-an-object-implementing-phalc","errorCode":null,"errorMessage":"Cache service must be an object implementing Phalcon\\Cache\\CacheInterface","messagePattern":"Cache service must be an object implementing Phalcon\\\\Cache\\\\CacheInterface","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Query\\Exceptions\\InvalidQueryCacheService","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Query.zep","lineNumber":360,"sourceCode":"            if unlikely typeof cacheOptions != \"array\" {\n                throw new InvalidCachingOptions();\n            }\n\n            /**\n             * The user must set a cache key\n             */\n            if unlikely !fetch key, cacheOptions[\"key\"] {\n                throw new MissingCacheKey();\n            }\n\n            if !fetch cacheService, cacheOptions[\"service\"] {\n                let cacheService = \"modelsCache\";\n            }\n\n            let cache = this->container->getShared(cacheService);\n\n            if unlikely (true !== is_a(cache,  CacheInterface::class)) {\n                throw new InvalidQueryCacheService();\n            }\n\n            /**\n             * If the lifetime is different than the cache lifetime, assign\n             * the cache lifetime to the current cache setting\n             */\n            let adapter       = cache->getAdapter();\n            let cacheLifetime = adapter->getLifetime();\n\n            if !fetch lifetime, cacheOptions[\"lifetime\"] {\n                let lifetime = cacheLifetime;\n            }\n\n            let result = false;\n            if (cache->has(key)) {\n                let result = cache->get(key);\n            }\n","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Query.zep#L342-L378","documentation":"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.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Query.zep:360 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Register a 'modelsCache' service returning a Phalcon\\Cache\\CacheInterface adapter","Point cacheOptions['service'] to an existing, correctly typed service name","Upgrade legacy cache services to the CacheInterface implementation"],"exampleFix":"$di->setShared('modelsCache', function () { return new Cache(new Libmemcached(new LibmemcachedOptions())); });","handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Type-hint and assert the cache service at bootstrap","Keep service definitions in a single DI configuration file"],"tags":[],"backgroundTag":null,"analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","contentChangedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}