cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG]: fatal error when using the model cache

Open ekmst opened this issue 7 years ago • 7 comments

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

ekmst avatar Sep 23 '19 19:09 ekmst

@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 avatar Sep 25 '19 06:09 ruudboon

@ruudboon Yes, I did. Thank!

ekmst avatar Sep 25 '19 06:09 ekmst

@ruudboon I think the problem is that json_decode returns an array by default

ekmst avatar Sep 25 '19 06:09 ekmst

@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.

ruudboon avatar Sep 25 '19 07:09 ruudboon

Resolved

niden avatar Sep 28 '19 16:09 niden

$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 avatar Nov 18 '19 02:11 bain2018

@bain2018 can you please open a new issue with what you are trying to store (and then seeing the error you are seeing)?

niden avatar Nov 18 '19 02:11 niden