$this->di->get('modelsCache')->queryKeys(); : unexpected behaviour
Questions should go to https://forum.phalconphp.com https://forum.phalconphp.com/discussion/12445/unexpected-behaviour-after-app-update-to-30-php7
Expected and Actual Behavior
Expected : return keys in cache Actual: a redirection occurs like the one acl do when not allowed
Describe what you are trying to achieve and what goes wrong. should return keys registered in cache, then in given example redirect to login page, instead redirect to "not allowed" acl default page
Provide output if related. Provide coredump if any.
no error in php log
Provide minimal script to reproduce the issue
/////////////// redis cache in services.php ////////////////////////////////////////
$di->setShared('modelsCache', function () {
$frontCache = new Phalcon\Cache\Frontend\Data(
array(
"lifetime" => 86400
)
);
//Create the Cache setting redis connection options
$cache = new Phalcon\Cache\Backend\Redis(
$frontCache, array(
'host' => '127.0.0.1',
'port' => 6379,
'auth' => '',
'persistent' => false,
));
return $cache;
});
///////////////// user login /////////////////////
///////////////// populating cache in controller (db: Postgres) /////////////////////
public function indexAction()
{
$articles = Articles::find(
array(
"cache" => array(
"key" => "articles-list"
)
)
);
.....
}
/////////////////// Trying to clear cache when logging out
public function endAction()
{
$keys = $this->di->get('modelsCache')->queryKeys(); // --> this line cause problem
foreach ($keys as $k) // --> not happening
{
$this->di->get('modelsCache')->delete($k);
}
$this->session->remove('auth'); // --> not happening
return $this->response->redirect('index/index'); // --> not happening
}
Details
- Phalcon version: 3.0
- PHP Version: PHP 7.0.9 (cli) (built: Jul 21 2016 14:50:47) ( NTS )
- Operating System: same error on mac os x and linux
- Installation type: Compiling from source
- Zephir version (if any):
- Server: Nginx (linux) | Apache (mac os x)
This script don't reproduce issue as it self. Just provide script that we can copy paste and have same unexpected behaviour.
Just post whole minimal script, best in one file to reproduce this problem. Like i can copy paste and that's it, have your problem. Right now you just posted some method, i don't even have service modelsCache by default in di, even if i would have - don't have any keys in it.
will try to do the backtrace thing, it's a full featured app, I'm not able to concatenate that in one script file...
Im not telling about posting your code and whole app here. Create one seperated file, do things which probably is causing this(like create di, create db, find something, put something in cache, try to delete keys,) and try to check if it's reproducing a problem ? And post this script here. For now i have:
Uncaught exception 'Phalcon\Di\Exception' with message 'Service 'modelsCache' wasn't found in the dependency injection container
You can use phalcon_test models, so no need to post sql to reproduce database.
script reproducing a problem != line(or few lines from your code) causing problem
I think it's typo, you define:
$di['modelCache'] = function() {}
But you call with:
$keys = $this->di->get('modelsCache')->queryKeys();
Can you try again with $di['modelsCache'] = function() {} ?
It should be modelsCache and you need to add 'statsKey'=>'_PHCR' to use queryKeys
I corrected typo, pasted from wrong source...
quote : you need to add 'statsKey'=>'_PHCR' to use queryKeys
thank you, that solved the issue, note that the doc doesn't refenrence this param.
But exception you should get yes :) Check your php configuration, there should be exception throwned.
https://github.com/phalcon/cphalcon/blob/master/phalcon/cache/backend/redis.zep#L328
You can close issue for now.