alaraiabdiallah / laravel-model-cache
Laravel 模型缓存
dev-master
2018-08-29 21:57 UTC
Requires
- php: ^7.0
This package is not auto-updated.
Last update: 2024-09-21 01:47:35 UTC
README
此包提供了一种简单的方式来缓存模型查询到集合。
安装
composer require "alaraiabdiallah/laravel-model-cache":"dev-master"
示例
您需要创建一个名为 Cache Query 的范围来注册查询缓存。以下示例将选择用户模型的所有数据并将其缓存:
<?php namespace App; use ModelCache\Contract as CacheContract; use ModelCache\Cacheable; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable implements CacheContract { use Notifiable,Cacheable; protected $fillable = [ 'name', 'email', 'password', ]; protected $hidden = [ 'password', 'remember_token', ]; public function scopeCacheQuery($query) { return $query->get(); } }