Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/authentikcanada/eloquent-cache
Easily cache your Laravel's Eloquent models.
https://github.com/authentikcanada/eloquent-cache
cache eloquent laravel php
Last synced: 7 days ago
JSON representation
Easily cache your Laravel's Eloquent models.
- Host: GitHub
- URL: https://github.com/authentikcanada/eloquent-cache
- Owner: AuthentikCanada
- License: gpl-3.0
- Created: 2018-08-07T14:47:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-21T17:05:43.000Z (over 1 year ago)
- Last Synced: 2024-03-14T14:02:56.769Z (8 months ago)
- Topics: cache, eloquent, laravel, php
- Language: PHP
- Size: 60.5 KB
- Stars: 58
- Watchers: 5
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Eloquent Cache
> Easily cache your Laravel's Eloquent models.
[![Build Status](https://travis-ci.org/AuthentikCanada/eloquent-cache.svg?branch=master)](https://travis-ci.org/AuthentikCanada/eloquent-cache)
[![Coverage Status](https://coveralls.io/repos/github/AuthentikCanada/eloquent-cache/badge.svg?branch=master)](https://coveralls.io/github/AuthentikCanada/eloquent-cache?branch=master)
[![Latest Stable Version](https://poser.pugx.org/authentik/eloquent-cache/v/stable.svg)](https://packagist.org/packages/authentik/eloquent-cache)
[![Total Downloads](https://poser.pugx.org/authentik/eloquent-cache/downloads.svg)](https://packagist.org/packages/authentik/eloquent-cache)## Requirements
- PHP >= 7.2
- Laravel 6 / 7 / 8
## Installation
Install via [composer](https://getcomposer.org/) :
`composer require authentik/eloquent-cache`
## How it works
- When Eloquent fetches models, the JSON representations of the model instances are cached.
- Subsequently, when eloquent fetches a model by ID, the cached JSON will be converted back into an instance.
## Usage
Use the `Cacheable` trait in the models you want to cache.
```php
no TTL)
public function getCacheTTL() {
return 60;
}// default value: the lowercase name of the model
public function getCacheTagName() {
return 'cat';
}// Cache busting will automatically invalidate the cache when model instances are updated or deleted.
// default value: true
public function isCacheBustingEnabled() {
return false;
}// Whether or not to keep model instances in a static array cache
// (useful to avoid querying the cache store/building instances from json multiple times)
// default value: true
public function isStaticCacheEnabled() {
return false;
}
}
```> To manually cache a model instance, use the `cache` method.
```php
Category::find(1)->cache();
```> To invalidate the cache for a model instance, use the `refresh` or `flush` method.
```php
$refreshedInstance = Category::find(1)->refresh();// or
Category::flush(Category::find(1));
```> To invalidate the cache for all instances of a model, use the `flush` method.
```php
Category::flush();
```## Changelog
[Click Here](CHANGELOG.md)