Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: fatal error when using the model cache #14408

Closed
ekmst opened this issue Sep 23, 2019 · 7 comments
Closed

[BUG]: fatal error when using the model cache #14408

ekmst opened this issue Sep 23, 2019 · 7 comments
Assignees
Labels
bug A bug report status: medium Medium

Comments

@ekmst
Copy link
Contributor

ekmst commented Sep 23, 2019

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
@ruudboon
Copy link
Member

@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',
];

@ekmst
Copy link
Contributor Author

ekmst commented Sep 25, 2019

@ruudboon Yes, I did. Thank!

@ekmst
Copy link
Contributor Author

ekmst commented Sep 25, 2019

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

@ruudboon
Copy link
Member

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

@niden
Copy link
Member

niden commented Sep 28, 2019

Resolved

@bain2018
Copy link

$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);

});

@niden
Copy link
Member

niden commented Nov 18, 2019

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

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

4 participants