amelia/rememberable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

amelia/rememberable

Composer 安装命令:

composer require amelia/rememberable

包简介

Query caching for Laravel 5

README 文档

README

Build Status

Rememberable is an Eloquent trait for Laravel 5.2+ that adds a transparent query cache to your models.

It works by simply remembering the SQL query that was used and storing the result. If the same query is attempted while the cache is persisted it will be retrieved from the store instead of hitting your database again.

Requirements

At current, you're required to be using Redis as your cache implementation.

This is planned to be changed in future, and pull requests are welcomed.

PHP 5.6+ is supported.

Note: This package will cause your increment/decrement operations on models that use it to fire the saved event afterwards. For most people, this should be of no concern, but to disable it, set protected static $interceptable = false.

Installation

Install using Composer, just as you would anything else.

composer require amelia/rememberable

The easiest way to get started with Eloquent is to create an abstract App\Model which you can extend your application models from. In this base model you can import the rememberable trait which will extend the same caching functionality to any queries you build off your model.

<?php

namespace App;

use Amelia\Rememberable\Rememberable;
use Illuminate\Database\Eloquent\Model as Eloquent;

abstract class Model extends Eloquent
{
    use Rememberable;
    
    /**
     * Remember _all_ queries on this model
     *
     * @var bool
     */
    protected static $rememberable = true;
}

Now, just ensure that your application models from this new App\Model instead of Eloquent.

Alternatively, you can simply apply the trait to each and every model you wish to use remember() on.

Usage

All queries are remembered automatically.

On update or delete, any query which contains the altered model will be removed from the cache.

This means that in almost all cases you can just set your base model to remember queries and forget about it.

Flushing

If you wish to flush the query cache manually, you can issue a Model::flush() command.

flush() takes cache tag arguments; the tags applied to every single query are the model's class name, the model's table name, and 'rememberable'.

So, to flush every query (say, during deployment, if you dont flush the entire cache), issue ::flush('rememberable') on any model in your application that uses rememberable.

Manual usage

Just like in watson/rememberable, you can use remember(int $minutes) on specific queries if you dont have $rememberable set to true on the model in use.

// Remember the number of users for an hour.
// remembers "select count(*) from users"
$users = User::remember(60)->count();

Credits

This package is under the MIT License.

It's a direct fork of watson/rememberable, with many added features.

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固