

GitHub - AuthentikCanada/eloquent-cache: Easily cache your Laravel's Elo...
source link: https://github.com/AuthentikCanada/eloquent-cache
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md
Eloquent Cache
Easily cache your Laravel's Eloquent models.
Requirements
-
PHP>=7.0
-
Laravel 5.5 or 5.6
Installation
Install via composer :
composer require authentik/eloquent-cache
How it works
-
When Eloquent fetches one or many models by ID (without eager-loading), 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 namespace App\Models; use Illuminate\Database\Eloquent\Model; use Authentik\EloquentCache\Cacheable; class Category extends Model { use Cacheable; /* * You can optionally override the following functions: */ // Time To Live in minutes (default value: 0 => 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.
Category::find(1)->cache();
To invalidate the cache for a model instance, use the
refresh
orflush
method.
$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.
Category::flush();
Recommend
-
89
Supercharged Excel exports and imports A simple, but elegant Laravel wrapper around PhpSpreadsheet exports and im...
-
85
Page not found · GitHub · GitHub Skip to content...
-
117
-
171
Build Eloquent queries from API requests This package allows you to filter, sort and include eloquent relations based on a request. The QueryBuilder used in this package extends Laravel's default Eloquent builder. This means...
-
140
laravel-model-caching - Eloquent model-caching made easy.
-
87
README.md Add schemaless attributes to Eloquent models
-
60
README.md Laravel Eloquent UUID
-
5
README.md The Laravel magic you know, now applied to joins. Joi...
-
8
Introduction Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Once Scout is installed and configured, it will automatically sync your model changes to your search indexes. Cu...
-
31
Associate comments and reactions with Eloquent models This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Support us We invest a lot of resources into creating
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK