Настройка компонента кэша Symfony 3.1 с помощью Redis


Я пытаюсь настроить кэш Symfony 3.1 с помощью Redis. Я следую этому руководству:

Https://symfony.com/blog/new-in-symfony-3-1-cache-component

Я установил predis/predis и SncRedisBundle.

В моем файле конфигурации.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

Теперь, когда я пытаюсь получить доступ к redis через snc_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. В журналах нет ничего что касается РЕДИСА.

Не могли бы вы сказать мне, где я допустил ошибку, или дать мне подсказку, что может быть не так?

Author: Robert, 2016-10-17

1 answers

Самое важное, что вы пропустили здесь, - это сохранить результат в кэш:

$cachedResources->set($resources);

$this->cacheAdapter->save($cachedResources);
 6
Author: malcolm, 2016-10-17 13:26:54