I try to setup Symfony 3.1 cache with Redis. I follow this tutorial:
https://symfony.com/blog/new-in-symfony-3-1-cache-component
I've installed predis/predis and SncRedisBundle.
In my config.yml I've put
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
Now when I try to access redis via snc_redis
it works normally. But when I try to use cache component:
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 is @cache.app
service.
It dumps all the time NOT_HIT
. In logs there is nothing regarding REDIS.
Could you tell me where I've made mistake or give me a hint what may be wrong?
The most important thing you missed here is to save result to cache:
$cachedResources->set($resources);
$this->cacheAdapter->save($cachedResources);