В случае, если это кому-то поможет, это решение я нашел.
Во-первых, мне нужно было установить zend-serializer, у меня уже был установлен zend-cache.
php composer require zendframework/zend-serializer
Затем в /config/autoload/global.php я добавил
'caches' => [
'RedisCache' => [
'adapter' => [
'name' => Redis::class,
'options' => [
'server' => [
'host' => '127.0.0.1',
'port' => '6379',
],
],
],
'plugins' => [
[
'name' => 'serializer',
'options' => [
],
],
],
],
],
В /config/application.config.php я добавил
'service_manager' => [
'factories' => [
\Zend\Cache\Storage\Adapter\Redis::class => InvokableFactory::class
]
]
Наконец, в моей фабрике контроллеровЯ настроил внедрение зависимости следующим образом:
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$cache = $container->get('RedisCache');
return new IndexController($cache);
}
Чтобы использовать кэширование в моем контроллере, я добавил кэширование в свой конструктор
public function __construct($cache)
{
$this->cache = $cache;
}
и в методе:
$this->cache->setItem('foo', 'bar');
echo $this->cache->getItem('foo');