PHPackages                             giver/cacheable - 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. giver/cacheable

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

giver/cacheable
===============

Query caching for Laravel 5

v1.1.0(7y ago)3293MITPHPPHP &gt;=5.4.0

Since Oct 4Pushed 7y ago2 watchersCompare

[ Source](https://github.com/claudioldf/cacheable)[ Packagist](https://packagist.org/packages/giver/cacheable)[ RSS](/packages/giver-cacheable/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (4)Versions (5)Used By (0)

Cacheable, Laravel 5 query cache
================================

[](#cacheable-laravel-5-query-cache)

Cacheable is an Eloquent trait for Laravel 5.0+ that brings back the `cache()` query functions from Laravel 4.2. This makes it super easy to cache your query results for an adjustable amount of time.

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

```

It works by simply cacheing 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 giver/cacheable

```

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 cacheable trait which will extend the same caching functionality to any queries you build off your model.

```
