mosamy/cacheable
最新稳定版本:1.0.2
Composer 安装命令:
composer require mosamy/cacheable
包简介
Laravel package for caching models
README 文档
README
Laravel eloquent model cache
Installation
composer require mosamy/cacheable
Usage
class Posts extends Model
{
use \Mosamy\Cacheable\Cacheable;
}
// this will get records from database.
$posts = Posts::get();
// this will get records from cache.
$posts = Posts::getCached();
//in shortcut
$posts = getCached('posts');
To search in cache result you may use this code
$posts = Posts::getCached()->searchCached('keyword', ['name', 'description']);
To set the default cache search attributes use this function:
class Posts extends Model
{
use \Mosamy\Cacheable\Cacheable;
public static function searchableAttributes(){
return ['name', 'description'];
}
}
$posts = Posts::getCached()->searchCached('keyword');
If you need to cache model with a relation or custom query you should override this function
class Posts extends Model
{
use \Mosamy\Cacheable\Cacheable;
public static function cache(){
return self::with('category')->get();
}
}
By default, Cache name format is: prefix(connection name)(table name) . By default there is no prefix for the cache name. If you want to set a cache prefix you should override this method.
class Posts extends Model
{
use \Mosamy\Cacheable\Cacheable;
public static function cache_prefix(){
return 'cache_';
}
}
So the default name will be like "cache_mysql_posts"
To delete cache you can use this method:
Post::deleteCache();
or simply clear all cache
php artisan cachhe:clear
统计信息
- 总下载量: 67
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-23