我尝试使用Redis设置Symfony 3.1缓存.我按照本教程:
https://symfony.com/blog/new-in-symfony-3-1-cache-component
我安装了predis / predis和SncRedisBundle.
在我的config.yml我已经把
framework:
cache:
app: cache.adapter.redis
default_redis_provider: redis://192.168.34.10
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://192.168.34.10
logging: %kernel.debug%
cache:
type: predis
alias: cache
dsn: redis://192.168.34.10
logging: %kernel.debug%
options:
connection_timeout: 10
read_write_timeout: 30
现在,当我尝试通过snc_redis访问redis时,它正常工作.但是当我尝试使用缓存组件时:
public function getLoggedUserAcl($userId)
{
$cachedResources = $this->cacheAdapter->getItem('acl.rules');
$cachedResources->expiresAfter(100);
if ($cachedResources->isHit()) {
dump('hit');
$resources = $cachedResources->get();
} else {
dump('not-hit');
$resources = $this->api->getCollection(Resource::class, null, null, [
'userId' => $userId
]);
$cachedResources->set($resources);
}
return $resources;
}
CacheAdapter是@ cache.app服务.
它一直转储NOT_HIT.在日志中,REdis没有任何内容.
你能告诉我哪里弄错了或者暗示我可能出错了吗?
解决方法:
您在这里错过的最重要的事情是将结果保存到缓存:
$cachedResources->set($resources);
$this->cacheAdapter->save($cachedResources);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。