PHPackages                             moocky/rememberable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. moocky/rememberable

ActiveLibrary[Database &amp; ORM](/categories/database)

moocky/rememberable
===================

Query caching for Laravel

v0.1.2(1y ago)15MITPHPPHP ^7.2.5|^8.0

Since Dec 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/moockymark/rememberable)[ Packagist](https://packagist.org/packages/moocky/rememberable)[ RSS](/packages/moocky-rememberable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (4)Used By (0)

基于watson/rememberable的Laravel Builder 请求缓存，实现count、max、min、sum、avg等的缓存，使用方法与原包完全相同

Rememberable is an Eloquent trait for Laravel that adds `remember()` query methods. This makes it super easy to cache your query results for an adjustable amount of time.

```
// Get a the first user's posts and remember them for a day.
User::first()->remember(now()->addDay())->posts()->get();

// You can also pass the number of seconds if you like (before Laravel 5.8 this will be interpreted as minutes).
User::first()->remember(60 * 60 * 24)->posts()->get();
```

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.

Installation
------------

[](#installation)

Install using Composer, just as you would anything else.

```
composer require moocky/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.

```
