PHPackages                             gnahotelsolutions/laravel-query-cache - 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. gnahotelsolutions/laravel-query-cache

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

gnahotelsolutions/laravel-query-cache
=====================================

Query caching for Laravel 6+

7.1.0(1y ago)37.6k↓33.3%MITPHPPHP ^8.2

Since Apr 21Pushed 1y agoCompare

[ Source](https://github.com/gnahotelsolutions/laravel-query-cache)[ Packagist](https://packagist.org/packages/gnahotelsolutions/laravel-query-cache)[ RSS](/packages/gnahotelsolutions-laravel-query-cache/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (27)Used By (0)

Laravel Query Cache
===================

[](#laravel-query-cache)

[![Total Downloads](https://camo.githubusercontent.com/1a6f51a2bb201254a85ebcc994887f7b9379d178c946c6bab0d285c71711f2fc/68747470733a2f2f706f7365722e707567782e6f72672f676e61686f74656c736f6c7574696f6e732f6c61726176656c2d71756572792d63616368652f646f776e6c6f6164732e737667)](https://packagist.org/packages/gnahotelsolutions/laravel-query-cache)[![Latest Stable Version](https://camo.githubusercontent.com/eb3f4e90d5646ac22c322467ff856f4d337c4386b6f1bb140ca5596940e4ef95/68747470733a2f2f706f7365722e707567782e6f72672f676e61686f74656c736f6c7574696f6e732f6c61726176656c2d71756572792d63616368652f762f737461626c652e737667)](https://packagist.org/packages/gnahotelsolutions/laravel-query-cache)[![Latest Unstable Version](https://camo.githubusercontent.com/4117f44f06ba91b4c4653b4abacde13c32d6c68280171e188c777fd151859681/68747470733a2f2f706f7365722e707567782e6f72672f676e61686f74656c736f6c7574696f6e732f6c61726176656c2d71756572792d63616368652f762f756e737461626c652e737667)](https://packagist.org/packages/gnahotelsolutions/laravel-query-cache)[![License](https://camo.githubusercontent.com/3a752396e8aaf4262372c2b7528496475d91a60cd8f2bafc4393ca5876ce17c0/68747470733a2f2f706f7365722e707567782e6f72672f676e61686f74656c736f6c7574696f6e732f6c61726176656c2d71756572792d63616368652f6c6963656e73652e737667)](https://packagist.org/packages/gnahotelsolutions/laravel-query-cache)

This package is forked from [dwightwatson/rememberable](https://github.com/dwightwatson/rememberable) for flexibility in our company projects. Thank you for your package [Dwight Watson](https://github.com/dwightwatson) ❤️

Laravel Query Cache 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 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.
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 gnahotelsolutions/laravel-query-cache
```

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.

```
