- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Laravel 的新手。我已经对这个主题进行了研究,但我似乎找不到能为我解决问题的答案。
我知道 Laravel 的默认缓存驱动程序设置为 file,我可以更改它。它还具有一些工匠缓存命令,例如:
php artisan config:cache
php artisan route:cache
1) 即使 Laravel 有一些内置的命令和功能可以自动处理一些缓存(不明白到底是什么部分),我仍然必须在查询结果上手动使用 Cache facade ,对吧?
它不会自动执行,如果我想更改某些东西或其他东西,我只需要使用 Cache facade,对吧?
这是教程中的一个随机示例:
$posts = Cache::remember('index.posts', 30, function()
{return Post::with('comments', 'tags', 'author', 'seo')->whereHidden(0)->get();});
2) 当使用 Redis(带有 predis 包)作为缓存驱动时,我需要使用 Cache facade 还是 Redis facade,或者两者都用一些案例?或者我可以简单地在 Laravel 和服务器(Forge 上的 Digital Ocean droplet)中启用 Redis 并且不做任何其他事情吗?
我在 Laravel 文档中看到过类似的东西,使用 Cache facade:
Cache::store('redis')->put('bar', 'baz', 600);
我还看过一个使用 Redis facade 的教程:
use Illuminate\Support\Facades\Redis;
Route::get('/', function () {
$visits = Redis::incr('visits');
return $visits;
});
我想不出什么是正确的做法。
最佳答案
它们都是缓存。
它们都是用来减少时间成本的。
它属于应用。我们称之为应用程序缓存。
php artisan config:cache
php artisan route:cache
这两条命令是缓存路由和配置。
They are always stored in
bootstrap/cache/
运行
php artisan config:clear
php artisan route:clear
只清除bootstrap/cache/
中的目录和文件。
它们是静态的。所以它们只有在您更改它们时才会更改。
如果您更改它们,您需要手动清除
并缓存
它们。
在你缓存这些路由和配置之后。
Laravel 不需要再次从文件中读取配置和路由,这会占用 IO 时间成本。
文件系统缓存和Redis缓存都是缓存。
但是,它们使用不同的驱动程序来存储数据,这意味着您在何处存储缓存数据。
Filesystem PATH: If you are using filesystem driver. they are stored in
storage/framework/cache/
Reids PATH: Datas store in
redis
by key-value.
当你发现有很多请求到这段代码获取数据时。而且这些数据并没有那么快变化。
您可以使用缓存来存储它们,然后,下次对这个 api 的另一个请求。它只是从缓存中获取数据。如下所示:
$posts = Cache::remember('index.posts', 30, function()
{return Post::with('comments', 'tags', 'author', 'seo')->whereHidden(0)->get();});
第一个请求从数据库中获取帖子的数据,然后将这些数据存储在 30 秒后过期的缓存(Reids 或文件系统)中。
下一个请求仅通过缓存获取帖子的数据。他们不需要再次在数据库中搜索。
还有这个:
use Illuminate\Support\Facades\Redis;
Route::get('/', function () {
$visits = Redis::incr('visits');
return $visits;
});
表示当人们请求localhost:8000/
时,用户在redis
中的访问次数增加(不需要存储在数据库中,需要更多时间),下次请求访问访问次数时,可以很快在redis
中查到。
PS: Here use Redis Facade, then the datas are stored in
redis
.If you are using redis as cache driver,
Cache::remember()
will store datas in redis too.However, using Redis Facade, you can use many redis methods.
我认为 redis
比 filesystem
好。
因为 redis
将数据存储在内存中,而文件系统存储在磁盘中。从内存中读取数据比磁盘更快。
在 Redis 中操作数据比文件系统容易。例如 Redis 支持清除特定标签的所有缓存,但文件系统不能[因为文件系统通过加密 key 的名称存储缓存数据]。
对于分布式服务器,文件系统缓存不是个好主意。较低的缓存命中率。
老实说,还有其他驱动可以选择,比如mongodb
。
顺便说一句,我的英语不是很好,希望你能理解。
关于laravel - 了解 Laravel 缓存 : Cache facade and Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58890788/
据我了解,立面图案的意图是 to provide a unified interface to a set of interfaces in a subsystem. Facade defines a
在我的独立(没有 Laravel)项目中,我想使用 Illuminate IoC 容器。我还想通过 illuminate/support 组件提供的 App facade 访问应用程序容器。我安装了这
我正在尝试制作一个简单的订购系统,因为这是一项作业,所以它是我不应该制作数据库和图形用户界面的界限,但我需要实现至少 4 个设计模式。我的决定之一是使用 Facade。据我了解,Facade 类是一种
概述 外部与内部子系统通信时必须通过的一个统一的外观模式对象进行,就是外观模式,也称门面模式。一般而言,Facade模式是为了降低客户端与实现化层之间的依赖性。外观模式的用意是为子系统提供一个集中
假设我们在 Laravel 中有以下类 class myClass { private $_someArray; // Functions to manipulate $_someAr
我的程序中的许多业务逻辑服务需要访问一组通用的非业务逻辑服务,例如电子邮件、打印、消息传递(消息框和提示)和日志记录。我计划创建一个外观来封装 EmailService、PrintService、Me
我经常看到有人这样使用门面。 public class FooFacade { Foo foo; public boolean isFunny(param1, param2) {
我的代码可以正常工作,但我不知道我的实现方式是否合适。基本上,我想保持模式而不违反它。 代码如下所示: 包模型(省略了 setter/getter): public class CA { pr
外观模式应该是程序员最下意识用的一种模式,比如我们习惯性的对复杂系统做一个封装接口。外观模式其本质是对一堆复杂对象和应用的接口抽象,对它们进行封装隔离,对于调用者来说只需要关系接口的实现,而不需要知
模式定义:外观模式(Facade Pattern):外部与一个子系统的通信必须通过一个统一的外观对象进行,为子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这一子系统更
外观模式(Facade Pattern)隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口 外观模式涉及到一个单一的类,该类提供了客户端请求的简化方法和对现有系统类方法的委托调用 外观
在处理我的第一个 laravel 包时遇到了我的 Facade 工作方式的问题,目前我的使用看起来像这样: {!! Custom::showValue() !}} //returns "default
我正在尝试使用配置 Controller 在 Laravel 7 中更改我的应用程序语言环境: class ConfigController extends Controller { /**
我有一个类(class)叫 Awesome并使用了 ServiceProvider和 Facade将其注册到应用程序。现在我可以将它用作 Awesome::Things() . 我想在这个类中添加常量
我们团队中的另一个人为我提供了一个库作为他的 Web 框架的 jar。我们将此框架称为“我 friend 的框架”。 我需要从他的框架中获取一个特定的类。该类公开的属性中有一半是我自己的应用程序真正需
我正在创建一个无状态 session bean(外观),它将用于“管理”特定实体,我们将其称为产品。将有添加新产品、更新现有产品、获取产品等的方法(我使用 Hibernate 进行持久化,因此我有一个
几年前,有人告诉我在单独的 .cs 文件中实现业务逻辑代码,尽管这些文件包装了相同的部分类。因此可以像这样从业务层调用方法: using(FooPartialDisposableClass parti
假设我的 Facade 类有两个子系统类。每个子系统都有不同的事件。 FacadeClass 是 public class FacadeClass { private SubsystemCla
我想知道这两种模式之间有什么区别。 我可能错了,但他们似乎在使用相同的结构来为更大的代码体实现更高级别的接口(interface)。 门面模式: var mobileEvent = { // ..
我写了一个任务管理器,好吧;说来话长……顺便说一句,全部用 Java 编写。所以我写了一个门面,你可以在下面看到 HashMap 有问题,我怀疑我在构建过程中尝试添加到 HashMap 中的值不太顺利
我是一名优秀的程序员,十分优秀!