PHPackages                             plug2team/model-cacheable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. plug2team/model-cacheable

ActiveLibrary[Caching](/categories/caching)

plug2team/model-cacheable
=========================

v0.5.1(6y ago)42MITPHPPHP ^7.4

Since Apr 21Pushed 6y ago1 watchersCompare

[ Source](https://github.com/plug2team/model-cacheable)[ Packagist](https://packagist.org/packages/plug2team/model-cacheable)[ RSS](/packages/plug2team-model-cacheable/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

Model Cacheable
===============

[](#model-cacheable)

Pacote para controlar cache em modelos.

Instalação
----------

[](#instalação)

> composer require plug2team/model-cached

Após a instalação do pacote, importe o arquivo de configuração:

> php artisan vendor:publish --tag=config

Configurando modelos
--------------------

[](#configurando-modelos)

Para seu modelo ser observado pelo cache, basta aplicar a trait `Cacheable` em sua model.

```
namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Plug2Team\ModelCached\Concerns\Cacheable;

class User extends Authenticatable
{
    use Cacheable;
```

em `AppServiceProvider` no metodo `boot` registre o modelo

```
    public function boot() {
        \App\User::crape();
    }
```

Utilidades
----------

[](#utilidades)

Registre os comandos auxiliares em `Console/Kernel.php`.

```
 $schedule->command('cacheable:flush')->cron(config('model_cached.commands.flush'));
 $schedule->command('cacheable:reindex')->cron(config('model_cached.commands.re_index'));
```

Como funciona
-------------

[](#como-funciona)

Após alguns testes, observei que é mais facil e eficiente gerenciar a persistencia de registros por agrupamento.

O agrupamento funciona assim:

1. Convertemos o nome da model de `App\User` para `user`.
2. Após termos o nome, criamos o grupo de indices para nome `user.indexes` onde guardamos e gerenciamos os `ids` recebimos por meio dos eventos do eloquente.
3. Tendo esses indices, o proximo passo é criar o agrupamento padrão o grupo `all` pode ser recuperado ` app('cacheable')->index('App\User')->group('all')->retrieve()`outra forma de recuperar esse grupo é chamando direto na model `\App\User::cache('all')`.
4. Para capturar os indices vinculados ao grupo `app('cacheable')->index('App\User')->group('all')->getIndexes()` ou `app('cache')->get('cached.{model}.{group}')` isso retornara a lista de ids vinculados ao grupo.

Recuperar indice
----------------

[](#recuperar-indice)

A estrutura de chaves é `.id`

Recuperar grupos
----------------

[](#recuperar-grupos)

Após registrar a model, passamos a monitorar os eventos do eloquente: `saved`,`deleted`,`retrieved`.

Para recupear um agrupamento é simples, basta informar o grupo em:

```
$users = \App\User::cache('all');
```

O grupo `all` é registrado por padrão, outros grupos podem ser registrados com sua arvores de chaves.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

2217d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/85234f9817ca9bcd1926d3dd205299cde47f2c15d9d48833701482d6fcd04097?d=identicon)[cesar-gutierres](/maintainers/cesar-gutierres)

---

Top Contributors

[![preetender](https://avatars.githubusercontent.com/u/14144294?v=4)](https://github.com/preetender "preetender (22 commits)")

### Embed Badge

![Health badge](/badges/plug2team-model-cacheable/health.svg)

```
[![Health](https://phpackages.com/badges/plug2team-model-cacheable/health.svg)](https://phpackages.com/packages/plug2team-model-cacheable)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[genealabs/laravel-model-caching

Automatic caching for Eloquent models.

2.4k4.8M26](/packages/genealabs-laravel-model-caching)[mikebronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k127.1k1](/packages/mikebronner-laravel-model-caching)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

2057.2k](/packages/iazaran-smart-cache)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k2.0k1](/packages/mike-bronner-laravel-model-caching)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
