lewis-neiland/laravel-cacheable-model

A package to manage caching Eloquent models and their relationships.

Installs: 17

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/lewis-neiland/laravel-cacheable-model

0.1.2 2024-06-22 13:19 UTC

This package is auto-updated.

Last update: 2025-12-09 12:06:12 UTC


README

Introduction

This is a simple solution to streamline using the Cache facade with Eloquent models and their relationships, primarily with the limitations of the default file driver. It provides methods to easily generate, retrieve and flush cached instances of Models in addition to any relationships in their model file specified via a function. Cache for a given model is automatically flushed upon any changes along with any cached relationships.

This was created for an earlier project, so that we could easily implement caching in our preestablished systems. As such, you can either use it as reference for your own software or improve on it.

All methods have appropriate documentation.

Note: Only supports caching of relationships that use an Eloquent Model.

Install via Composer (WIP):

In your Laravel project's root directory, run: composer require lewis-neiland/laravel-cacheable-model. This will install the needed files to your project.

Getting Started:

Importing

In any Eloquent Model file you wish to use this for, add the following as seen here:

use CacheableModel;

class Model
{
    use CacheableModel;
}