Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/simplesoftwareio/simple-cache
- Owner: SimpleSoftwareIO
- License: mit
- Created: 2016-12-19T02:26:55.000Z (almost 8 years ago)
- Default Branch: develop
- Last Pushed: 2022-05-17T12:44:38.000Z (over 2 years ago)
- Last Synced: 2024-10-29T21:06:02.950Z (15 days ago)
- Topics: cache, eloquent, laravel, laravel-package
- Language: PHP
- Size: 17.6 KB
- Stars: 23
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
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)
#### 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.
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();