如何在Laravel 6.X中传递符合PSR-6的缓存适配器? [英] How to pass a PSR-6 compliant cache adapter in Laravel 6.X?
问题描述
我注意到有一个cache.psr6容器别名,但是如果我使用:
I note there is a cache.psr6 container alias but if I use:
new Cache
作为实例,我收到一个错误,指出getItems不可用,我认为这意味着我没有传递PSR-6兼容的缓存实例.如果正在以任何方式更改配置,我将使用Redis.
As the instance, I get an error that getItems isn't available, which, I assume, means I am not passing a PSR-6 compliant cache instance. I'm using Redis if that changes the config in any way.
是否还有其他配置需要完成?还是我以错误的方式传递了此信息?
Is there an additional configuration to be done or am I passing this the wrong way?
我正在使用的库为: https://github.com/AlexaCRM/dynamics-webapi-toolkit/wiki/教程
本教程指出:
您可以选择提供符合PSR-6的缓存适配器.
You can optionally supply a PSR-6 compliant cache adapter.
$ settings-> cachePool = $ cacheAdapter;
$settings->cachePool = $cacheAdapter;
我的问题是,什么是$ cacheAdapter?
My question is, what is $cacheAdapter?
推荐答案
适配器将是 Psr16Adapter
通过缓存驱动程序,这是将cache.psr6
绑定到默认
The adapter would be a Psr16Adapter
over a cache driver which is how cache.psr6
is bound in the default CacheServiceProvider
.
如果已将Redis配置为默认缓存驱动程序,则只需将缓存池设置为cache.psr6
.
If you have redis configured as your default cache driver you would only need to set your cache pool to cache.psr6
.
$settings->cachePool = app('cache.psr6');
但是,由于symfony/cache
只是laravel/framework
中的dev依赖项,因此您可能会遇到Class 'Symfony\Component\Cache\Adapter\Psr16Adapter' not found
错误.您可以通过在应用程序中要求它来解决此问题.
However you may run into a Class 'Symfony\Component\Cache\Adapter\Psr16Adapter' not found
error since symfony/cache
is only a dev dependency in laravel/framework
. You can resolve this by requiring it in your application.
composer require symfony/cache
这篇关于如何在Laravel 6.X中传递符合PSR-6的缓存适配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!