Describe the bug
fatal error when using the model cache
To Reproduce
Steps to reproduce the behavior:
// services: modelsCache
$serializerFactory = new SerializerFactory();
$adapterFactory = new AdapterFactory($serializerFactory);
$options = [
'defaultSerializer' => 'Json',
'lifetime' => 30,
'cacheDir' => 'cache/models',
];
$adapter = $adapterFactory->newInstance('stream', $options);
$cache = new Cache($adapter);
$di->set('modelsCache', $cache);
// controller
$options['cache'] = [
'key' => 'uniqkey',
'lifetime' => 50,
];
$result = Users::find($options);
// output:
Fatal error: Uncaught Phalcon\Mvc\Model\Exception: Cache didn't return a valid resultset in phalcon/Mvc/Model/Query.zep on line 3672
Details
Version => 4.0.0-rc.1
Build Date => Sep 23 2019 13:10:02
Powered by Zephir => Version 0.12.4-b386980
Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.case_insensitive_column_map => Off => Off
phalcon.orm.cast_last_insert_id_to_int => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.disable_assign_setters => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.exception_on_failed_metadata_save => On => On
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.virtual_foreign_keys => On => On
@ekmst I think I located the issue. Will try to bug fix this soon.
Probally this will work if you set your serialiser to Php.
$adapterFactory = new AdapterFactory($serializerFactory);
$options = [
'defaultSerializer' => 'Php',
'lifetime' => 30,
'cacheDir' => 'cache/models',
];
@ruudboon Yes, I did. Thank!
@ruudboon I think the problem is that json_decode returns an array by default
@ruudboon Yes it's related to that. But not directly on the serializer. We also have this with the None serializer.
There are few ways to fix this. Just need to figure out the best way. Will check this later today.
Resolved
$di->setShared('modelsCache', function () {
$config = $this->getConfig();
$serializerFactory = new \Phalcon\Storage\SerializerFactory();
$adapterFactory = new \Phalcon\Cache\AdapterFactory($serializerFactory);
$options = [
//here get an errror:Cache didn't return a valid resultset ,but change defaultSerializer to Php it works well
'defaultSerializer' => 'Json',
'lifetime' => 7200,
'host' => $config->redis->host,
'port' => $config->redis->port,
'auth' => $config->redis->auth,
'persistent' => $config->redis->persistent,
'index' =>1,
'storageDir' => STORAGE_PATH.'cache/',
];
$adapter = $adapterFactory->newInstance('redis', $options);
return new \Phalcon\Cache($adapter);
});
@bain2018 can you please open a new issue with what you are trying to store (and then seeing the error you are seeing)?
Most helpful comment
Resolved