How to pass a PSR-6 compliant cache adapter in Laravel 6.X?

限于喜欢 提交于 2020-01-25 07:25:47

问题


I note there is a cache.psr6 container alias but if I use:

new Cache

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?

The library I am using is: https://github.com/AlexaCRM/dynamics-webapi-toolkit/wiki/Tutorial

And the tutorial states:

You can optionally supply a PSR-6 compliant cache adapter.

$settings->cachePool = $cacheAdapter;

My question is, what is $cacheAdapter?


回答1:


The adapter would be a Psr16Adapter over a cache driver which is how cache.psr6 is bound in the default CacheServiceProvider.

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');

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


来源:https://stackoverflow.com/questions/59198899/how-to-pass-a-psr-6-compliant-cache-adapter-in-laravel-6-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!