Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/simplesoftwareio/simple-cache

An easy to use Caching trait for Laravel's Eloquent Models.
https://github.com/simplesoftwareio/simple-cache

cache eloquent laravel laravel-package

Last synced: 6 days ago
JSON representation

An easy to use Caching trait for Laravel's Eloquent Models.

Awesome Lists containing this project

README

        

Simple Cache
========================

[![Build Status](https://travis-ci.org/SimpleSoftwareIO/simple-cache.svg?branch=master)](https://travis-ci.org/SimpleSoftwareIO/simple-cache)
[![Latest Stable Version](https://poser.pugx.org/simplesoftwareio/simple-cache/v/stable.svg)](https://packagist.org/packages/simplesoftwareio/simple-cache)
[![Latest Unstable Version](https://poser.pugx.org/simplesoftwareio/simple-cache/v/unstable.svg)](https://packagist.org/packages/simplesoftwareio/simple-cache)
[![License](https://poser.pugx.org/simplesoftwareio/simple-cache/license.svg)](https://packagist.org/packages/simplesoftwareio/simple-cache)
[![Total Downloads](https://poser.pugx.org/simplesoftwareio/simple-cache/downloads.svg)](https://packagist.org/packages/simplesoftwareio/simple-cache)

- [Introduction](#docs-introduction)
- [Configuration](#docs-configuration)
- [Usage](#docs-usage)

## Try our dead simple, free file transfer service [keep.sh](https://keep.sh)


## Configuration

#### Composer

First, add the Simple Cache package to your `require` in your `composer.json` file:

"require": {
"simplesoftwareio/simple-cache": "~1"
}

Next, run the `composer update` command.


## Usage

The cacheable trait may be used by adding the trait to the Eloquent model of your choice.

Be careful! Eloquent Model's with a high amount of insert/update/delete traffic should not use the cache busting feature. The large amount of changes will invalid the model too often and cause the cache to be useless. It is better to set a lower cache length to invalid the results frequently if up to date data is required.

### Methods

#### flush()

The `flush` method will flush the cache for a model.

(new User)->flush() //Cache is flushed for the `User` model.

#### isBusting()

`isBusting` will return the current status of the `cacheBusting` property.

if((new User)->isBusting()) {
// Is cache busting
}

#### remember($length)

`remember` will set the length of time in minutes to remember an Eloquent query.

User::remember(45)->where('id', 4')->get();

#### rememberForever()

`rememberForever` will remember a query forever. Well, technically 10 years but lets pretend it is forever eh?

User::rememberForever()->where('id', 4')->get();

#### dontRemember()

And lastly, `dontRemember` will not cache a query result.

User::dontRemember(0)->where('id', 4')->get();