[BUG]: Phalcon v5.0.0-alpha.2 - whats wrong with models cache?
Describe the bug
I try to migrate to Phalcon v.5 (php8) or just still try it with my project- need to be sure they will work fine with next releases. And yes, they works almost fine... except something with cache stuff. The error i get is:
Fatal error: Uncaught TypeError: Phalcon\Mvc\Model\Resultset\Simple::__construct(): Argument #4 ($cache) must be of type ?Phalcon\Cache\Adapter\AdapterInterface, Phalcon\Cache given in v1\modules\client\controllers\ControllerBase.php on line 33
So, in this line i have:
$articles = \Models\Articles::find([
'conditions' => 'is_global=1',
'cache' => [
'key' => 'global-articles'
]
]);
... and see is something related with models cache service. Its init like that:
/*
* Set the models cache service
*/
$di->set('modelsCache', function () use ($config) {
$lifetime = 60 * 60 * 24 * 7; // 7 days
if ($config->development) {
$lifetime = 60; // 1 min
}
// Create folder if did not exists
$folder = BASE_PATH . 'cache/queries/';
$serializerFactory = new \Phalcon\Storage\SerializerFactory();
$adapter = new \Phalcon\Cache\Adapter\Stream($serializerFactory, [
'storageDir' => $folder,
'lifetime' => $lifetime
]);
$cache = new \Phalcon\Cache($adapter);
return $cache;
});
Soo... maybe the mistake is Phalcon\Cache, but this works in Phalcon 4.x. So how must be changed?
Thanks :) And may the force be with you!
Details
- Phalcon version: v5.0.0-alpha.2
- PHP Version: 8.0.6
- Operating System: Windows
- Server: Apache
Can you provide code part around this line?
v1\modules\client\controllers\ControllerBase.php on line 33
I suppose you providing wrong object.
As is see in error, you trying to:
$simpleResultset = new Simple($columnMap, $model, $resultset, $this->modelsCache);
Can you try next change?
$simpleResultset = new Simple($columnMap, $model, $resultset, $this->modelsCache->getAdapter());
Line 33 is that line with "key=" from ::find, but i will be more specific later, just to back home.

I think now its better. I did not have "$simpleResultset" but if u want me to try something... i am here! I will try to debug some more.

Can you try this one?
$di->set('modelsCache', function () use ($config) {
$serializerFactory = new \Phalcon\Storage\SerializerFactory();
return new \Phalcon\Cache\Adapter\Stream($serializerFactory, [
'storageDir' => BASE_PATH . 'cache/queries/',
'lifetime' => $config->development ? 60 : 60 * 60 * 24 * 7,
]);
});
I confirm that this work in Phalcon 4x and Phalcon 5.0.0 alpha-2. If that is the way to set cache service- documentation must be fixed here: https://docs.phalcon.io/4.0/en/db-models-cache#resultsets (i can do that...). I am pretty sure there is more places with that service examples and i will find them.
I will test other type of cache to see if all works fine.
Well... thanks! A lot :) U awesome!
If that is the way to set cache service- documentation must be fixed here...
Its only related to modelsCache service due to the way Query using it.
@BeMySlaveDarlin so its not related with other cache stuff? Ok, cool. Thanks Anyway, is here must be fixed too: https://docs.phalcon.io/4.0/en/cache#cache-1 ?
Nope, only modelsCache service. The rest of services works fine.
Lov u guys xD ... Cant wait Phalcon 6... then i can contribute and help more.
Best wishes.
I actually managed to reproduce this. It only happens in PHP 8 and the solution is to use CacheInterface vs AdapterInterface
I should have something ready very soon.
Fixed in #15478