laravel Lumen 文件缓存驱动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34535215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Lumen file cache driver
提问by Andrea
I'm in Lumen, inside a Controller, and I would like to cache a computation's result in a simple and easy way, without using database or external services, so I was looking for save the cache in the filesystem. In Laravel's documentationthere is cited the file
driver:
我在 Lumen 中,在一个控制器中,我想以一种简单易行的方式缓存计算结果,而不使用数据库或外部服务,所以我正在寻找将缓存保存在文件系统中。在Laravel 的文档中引用了file
驱动程序:
By default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the filesystem.
默认情况下,Laravel 配置为使用文件缓存驱动程序,它将序列化的缓存对象存储在文件系统中。
And I can see it, configured as Default Cache Store, inside config/cache.php
.
我可以看到它,配置为Default Cache Store,在config/cache.php
.
In Lumen's documentationi can't see anything about the file driver and I find nothing like the file cache.php
inside Lumen installation.
在Lumen 的文档中,我看不到任何有关文件驱动程序的信息,而且我cache.php
在 Lumen 安装中找不到与该文件类似的内容。
So my question is if I can use the file cache driver in Lumen (by setting CACHE_DRIVER=file
) or if it is discouraged, not supported, not implemented or something else?
所以我的问题是我是否可以在 Lumen 中使用文件缓存驱动程序(通过设置CACHE_DRIVER=file
),或者是否不鼓励、不支持、未实现或其他什么?
回答by Marcin Nabia?ek
In Lumen in .env.example
you have by default:
在 Lumen 中,.env.example
您默认拥有:
CACHE_DRIVER=memcached
So all you need is to change filename from .env.example
to .env
and set
所以你所需要的就是将文件名从.env.example
to更改为.env
并设置
CACHE_DRIVER=file
If you read Caching in Lumenyou'll see in example:
如果您阅读Lumen 中的缓存,您将在示例中看到:
$value = Cache::store('file')->get('foo');
so file
driver is supported by Lumen.
所以file
驱动是由 Lumen 支持的。
If you also read Lumen Configurationyou can read here that you can copy configuration files you need (in case you need them) and load them manually. You can see default Luman cache config file here: https://github.com/laravel/lumen-framework/blob/5.1/config/cache.php
如果您还阅读了Lumen 配置,您可以在此处阅读,您可以复制您需要的配置文件(以防万一)并手动加载它们。你可以在这里看到默认的 Luman 缓存配置文件:https: //github.com/laravel/lumen-framework/blob/5.1/config/cache.php