使用Laravel的缓存组件(Illuminate/Cache
)作为我的应用的后端缓存,如何注册新的自定义缓存驱动程序?由于我根本不使用Laravel(只有Illuminate/Cache
),所以我无法将其添加到服务提供商,并且Cache
外观返回并显示错误。在独立Laravel缓存实例中添加自定义缓存驱动程序
请注意,我成功地使用默认的驱动程序(文件,memcached的,Redis的)使用singleton
函数传递配置和这样的空Illuminate\Container\Container
内:
编辑 - 示例代码我如何获得高速缓存商店:
$app = new Illuminate\Container\Container();
// Where $config is an array of config values
$app->singleton('config', function() use ($config) {
return $config;
});
$app->singleton('files', function() {
return new Illuminate\Filesystem\Filesystem();
});
$cacheManager = new CacheManager($app);
// Where $storeName is linked to the configs values
return $cacheManager->store($storeName);
你可以告诉你代码,如果你“在一个空的'Illuminate \ Container \ Container'中传递配置等等”? :) –
编辑问题 –
https://laravel.com/docs/5.4/cache#adding-custom-cache-drivers。只需用'CacheManager'实例替换'Cache'外观,例如'$ cacheManager-> extend(...)' –