当前位置:网站首页>Laravel 的 ORM 缓存包
Laravel 的 ORM 缓存包
2022-06-27 02:09:00 【lenixa】
Laravel 的 ORM 缓存包
LaraCache是一个基于 ORM 的 Laravel 包,用于基于模型查询创建、更新和管理缓存项。使用此包,您可以缓存在整个应用程序中大量使用的查询。
use Mostafaznv\LaraCache\Traits\LaraCache;
class Article extends Model
{
use LaraCache;
public static function cacheEntities(): array
{
return [
CacheEntity::make('list.forever')
->cache(function() {
return Article::query()->latest()->get();
}),
CacheEntity::make('latest')
->validForRestOfDay()
->cache(function() {
return Article::query()->latest()->first();
})
];
}
}使用该cacheEntities方法定义缓存查询,Laracache 将负责其余的工作。要使用缓存查询,您将调用模型,如下例所示:
use Mostafaznv\LaraCache\Facades\LaraCache;
$cache = Article::cache()->get('latest');
// or
$cache = LaraCache::retrieve(Article::class, 'latest');使用此软件包,您可以使用以下功能控制缓存:
- 启用/禁用缓存
- 手动更新缓存
- 手动更新所有缓存实体
- 删除缓存
CacheEntity使用流利的方法或ttl()方法控制持续时间
我认为以下手动缓存更新方法很简洁,可以即时刷新缓存:
Article::cache()->update('latest');
// or
LaraCache::update(Article::class, 'latest');边栏推荐
- 达梦数据库安装
- Canvas particles: mouse following JS effect
- Parameter transfer method between two pages
- 我靠副业一个月挣了3W块:你看不起的行业,真的很挣钱!
- Don't be brainwashed. This is the truth about the wages of 90% of Chinese people
- “所有专业都在劝退”,对大学生最友好的竟然是它?
- Summary of config mechanism and methods in UVM (2)
- Yalm 100b: 100billion parameter open source large model from yandex, Russia, allowing commercial use
- Dameng database installation
- lottie. JS creative switch button animal head
猜你喜欢
Reading a book in idea is too much!

谷歌开始卷自己,AI架构Pathways加持,推出200亿生成模型

STM32入门介绍

Don't be brainwashed. This is the truth about the wages of 90% of Chinese people

1、项目准备与新建

学习DiscoDiffusion的最基础操作

three. JS domino JS special effect

解决cherry pick提交报错问题

Why pass SPIF_ Sendchange flag systemparametersinfo will hang?

按键控制LED状态翻转
随机推荐
paddlepaddle 20 指数移动平均(ExponentialMovingAverage,EMA)的实现与使用(支持静态图与动态图)
Oracle/PLSQL: NumToDSInterval Function
CVPR2022 | PointDistiller:面向高效紧凑3D检测的结构化知识蒸馏
DAMA、DCMM等数据管理框架各个能力域的划分是否合理?有内在逻辑吗?
1、项目准备与新建
Parameter estimation -- Chapter 7 study report of probability theory and mathematical statistics (point estimation)
P5.js death planet
XSS攻击(笔记)
Addition, deletion, modification and query of ymal file
Oracle/PLSQL: Substr Function
C language -- Design of employee information management system
速看!2022年6月编程语言排行榜出炉!第一名太牛啦
STM32入门介绍
Some exception handling for idea plug-in development
I earned 3W yuan a month from my sideline: the industry you despise really makes money!
Oracle/PLSQL: Ltrim Function
Topolvm: kubernetes local persistence scheme based on LVM, capacity aware, dynamically create PV, and easily use local disk
Binary tree OJ problem
numpy 数组运算机制浅探
memcached基礎12