当前位置:网站首页>ORM cache package for laravel
ORM cache package for laravel
2022-06-27 02:15:00 【lenixa】
Laravel Of ORM Cache package
LaraCache It's based on ORM Of Laravel package , Used to create... Based on model queries 、 Update and manage cache entries . Use this package , You can cache queries that are heavily used throughout your application .
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();
})
];
}
} Use this cacheEntities Method to define a cache query ,Laracache Will be responsible for the rest of the work . To use cached queries , You will invoke the model , As shown in the following example :
use Mostafaznv\LaraCache\Facades\LaraCache;
$cache = Article::cache()->get('latest');
// or
$cache = LaraCache::retrieve(Article::class, 'latest');Use this package , You can use the following functions to control the cache :
- Enable / Disable caching
- Manually update cache
- Manually update all cached entities
- Delete cache
CacheEntityUse fluent methods orttl()Method control duration
I think the following manual cache update method is simple , The cache can be refreshed immediately :
Article::cache()->update('latest');
// or
LaraCache::update(Article::class, 'latest');You can learn about this bag , Get complete installation instructions , And in GitHub Check out Source code .
边栏推荐
猜你喜欢

学习太极创客 — MQTT 第二章(二)ESP8266 QoS 应用

canvas粒子篇之鼠标跟随js特效

Cvpr2022 | pointdistiller: structured knowledge distillation for efficient and compact 3D detection

three.js多米诺骨牌js特效

three. JS domino JS special effect

学习太极创客 — MQTT(七)MQTT 主题进阶

Constraintlayout Development Guide

Arbre binaire OJ sujet

学习太极创客 — MQTT(六)ESP8266 发布 MQTT 消息

执念斩长河暑期规划
随机推荐
Oracle/PLSQL: Trim Function
Arbre binaire OJ sujet
Oracle/PLSQL: Trim Function
Yalm 100b: 100billion parameter open source large model from yandex, Russia, allowing commercial use
Shell script series (1) getting started
Parameter estimation -- Chapter 7 study report of probability theory and mathematical statistics (point estimation)
XSS attack (note)
Oracle/PLSQL: Ltrim Function
学习太极创客 — MQTT 第二章(一)QoS 服务质量等级
jwt的认证流程和使用案例
Flink Learning 2: Application Scenarios
Oracle/PLSQL: Length Function
memcached基础15
平均风向风速计算(单位矢量法)
Flink learning 5: how it works
Press key to control LED status reversal
canvas粒子篇之鼠标跟随js特效
Topolvm: kubernetes local persistence scheme based on LVM, capacity aware, dynamically create PV, and easily use local disk
1、项目准备与新建
Oracle/PLSQL: Ltrim Function