承接 mosamy/cacheable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-23