Cphalcon: [BUG]: fatal error when using the model cache

Created on 23 Sep 2019  路  7Comments  路  Source: phalcon/cphalcon

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

  • Phalcon version: 4.0.0-rc.1
  • PHP Version: 7.3.1
  • Operating System: linux (ubuntu18.04)
  • Installation type: installing via package manager
  • Server: Nginx
  • Other related info (Database, table schema): mysql
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
bug medium

Most helpful comment

Resolved

All 7 comments

@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)?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yakovlev-Melarn picture Yakovlev-Melarn  路  3Comments

hailie-rei picture hailie-rei  路  3Comments

alvassin picture alvassin  路  3Comments

masood09 picture masood09  路  4Comments

ismail0234 picture ismail0234  路  3Comments