定制 farzinft/laravel-model-caching 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

farzinft/laravel-model-caching

Composer 安装命令:

composer require farzinft/laravel-model-caching

包简介

Simple Way Of Caching Laravel Eloquent Query Results

README 文档

README

For Laravel 5.x.x

This is a package to cache your eloquent query results.

Installation

Require this package in your composer.json and run composer update (or run composer require farzinft/laravel-model-caching:dev-master directly):

"farzin/laravel-model-caching": "dev-master"

You need to publish the config file for this package. This will add the file config/model-caching.php, where you can configure this package.

$ php artisan vendor:publish --provider="Fthi\ModelCaching\ServiceProvider"

Usage

You just need add your model to model caching construct and write your eloquent queries in a normal way. this package uses Redis for caching results;

Example:

suppose you have a customer model and you wrote a query like this:

without cache:

 "$customers = Customer::with('books')->where(['status' => 1])->get()"

and you want cache result 50 seconds, change cache_expire_time (in second) in model-caching.php or inside your model define a public variable named $cacheExpireTime, then:

with cache:

"$customers = (new ModelCaching(new Customer))->with('books')->where(['status' => 1])->get()"

when cache time expired results back from database.

just tested on laravel 5.x, maybe it works on other versions, test it :)

统计信息

  • 总下载量: 1.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-12-25