PHPackages                             laravel-enso/rememberable - 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. laravel-enso/rememberable

ActiveLibrary[Caching](/categories/caching)

laravel-enso/rememberable
=========================

Model caching dependency for Laravel Enso

4.0.2(2mo ago)2864.9k↓15.5%420MITPHPPHP ^8.0CI failing

Since May 9Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/laravel-enso/rememberable)[ Packagist](https://packagist.org/packages/laravel-enso/rememberable)[ Docs](https://github.com/laravel-enso/rememberable)[ RSS](/packages/laravel-enso-rememberable/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (86)Used By (20)

Rememberable
============

[](#rememberable)

[![License](https://camo.githubusercontent.com/5e0339d43c08064d17d7483be9bb8040e08c6e048df8f72d0edb15863c7aaa3d/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f72656d656d62657261626c652f6c6963656e7365)](LICENSE)[![Stable](https://camo.githubusercontent.com/b5bb826ba2a918ff7a8fafcde5864b34067c95187ae3adb29e0a9a1474272c7b/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f72656d656d62657261626c652f76657273696f6e)](https://packagist.org/packages/laravel-enso/rememberable)[![Downloads](https://camo.githubusercontent.com/59895690e8a2c1f721ee1d05d55989a3eff7ea92c94608255ab0ea808ea23c3f/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f72656d656d62657261626c652f646f776e6c6f616473)](https://packagist.org/packages/laravel-enso/rememberable)[![PHP](https://camo.githubusercontent.com/ef6afd4ccdaa708a9b1a0a353d6d03a13ca1f03887b8db701d4118dc30a6735a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e302532422d3737376262342e737667)](composer.json)[![Issues](https://camo.githubusercontent.com/b71a1ca6a705d00aec06e84f0a8f73a141b8498e5e27643b56e83af3b5b7b92d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c61726176656c2d656e736f2f72656d656d62657261626c652e737667)](https://github.com/laravel-enso/rememberable/issues)[![Merge Requests](https://camo.githubusercontent.com/a7cba1240cf433bef0be0516873cd95a973705586a19a44150807524ec561075/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6c61726176656c2d656e736f2f72656d656d62657261626c652e737667)](https://github.com/laravel-enso/rememberable/pulls)

Description
-----------

[](#description)

Rememberable adds model-level caching to Eloquent models that are frequently resolved by stable lookup keys.

The package hooks into model lifecycle events, stores models in Laravel's cache when they are created or updated, clears cached entries when they are deleted, and exposes convenience accessors for resolving records by `id` or by any configured alternate key.

In the Enso ecosystem it is used for lookup-oriented models such as countries, categories, measurement units, settings, products, and other entities that benefit from repeated reads by code, name, slug, or external identifiers.

Installation
------------

[](#installation)

This package is typically installed transitively by Enso packages that rely on cached lookup models.

For standalone installation:

```
composer require laravel-enso/rememberable
```

The package auto-registers its service provider and merges the `enso.rememberable` configuration.

If you want to publish the config locally:

```
php artisan vendor:publish --tag=rememberable-config
```

The default configuration is:

```
return [
    'cacheLifetime' => (int) env('CACHE_LIFETIME', 3600),
    'keys' => ['id'],
];
```

Features
--------

[](#features)

- Caches models automatically on `created` and `updated`.
- Removes cached entries automatically on `deleted`.
- Supports cached lookup by primary key through `cacheGet()`.
- Supports cached lookup by additional configured keys through `cacheGetBy()`.
- Lets each model override the cache lifetime.
- Lets each model declare its own rememberable keys.
- Rehydrates cache transparently when a key is not already cached.
- Keeps subclasses isolated because cache keys are built from the static model class.

Usage
-----

[](#usage)

Apply the trait to an Eloquent model:

```
use Illuminate\Database\Eloquent\Model;
use LaravelEnso\Rememberable\Traits\Rememberable;

class Company extends Model
{
    use Rememberable;

    protected $rememberableKeys = ['id', 'name', 'fiscal_code'];
}
```

Resolve a model by primary key:

```
$company = Company::cacheGet(1);
```

Resolve a model by another configured key:

```
$company = Company::cacheGetBy('name', 'Earthlink');
```

Customize the cache lifetime per model:

```
class Product extends Model
{
    use Rememberable;

    protected $cacheLifetime = 100;
}
```

You can also cache records forever:

```
class Setting extends Model
{
    use Rememberable;

    protected $cacheLifetime = 'forever';
}
```

::: warning Note `cacheGetBy()` only works for keys declared in the model's `rememberableKeys` property or in the global `enso.rememberable.keys` config.

If a key is not allowed, the package throws a `LaravelEnso\Rememberable\Exceptions\Rememberable` exception. :::

API
---

[](#api)

### Configuration

[](#configuration)

`config/rememberable.php`

Keys:

- `cacheLifetime`
- `keys`

### Trait

[](#trait)

`LaravelEnso\Rememberable\Traits\Rememberable`

Lifecycle hooks:

- caches the model on `created`
- refreshes the cached model on `updated`
- removes cached entries on `deleted`

Public methods:

- `cacheGet($id)`
- `cacheGetBy(string $key, $value)`
- `cachePut()`
- `cacheForget()`
- `getCacheKey(string $key, $value = null): string`

Protected extension points:

- `$cacheLifetime`
- `$rememberableKeys`
- `getCacheLifetime()`
- `cacheableKeys()`

Cache key format:

```
::

```

### Exception

[](#exception)

`LaravelEnso\Rememberable\Exceptions\Rememberable`

Currently exposes:

- `missingKey(string $key): self`

Depends On
----------

[](#depends-on)

Framework dependency:

- [`laravel/framework`](https://github.com/laravel/framework) [↗](https://github.com/laravel/framework)

Contributions
-------------

[](#contributions)

are welcome. Pull requests are great, but issues are good too.

Thank you to all the people who already contributed to Enso!

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity39

Limited adoption so far

Community32

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 59.7% 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 ~44 days

Recently: every ~139 days

Total

75

Last Release

74d ago

Major Versions

1.5.1 → 2.0.02019-04-16

2.2.4 → 3.0.02020-06-25

3.6.0 → 4.0.02026-04-09

PHP version history (5 changes)1.0.0PHP &gt;=5.6.4

1.1.2PHP &gt;=7.1.0

2.2.0PHP &gt;=7.4.0

3.2.6PHP &gt;=8.0

3.4.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16073274?v=4)[Adrian Ocneanu](/maintainers/aocneanu)[@aocneanu](https://github.com/aocneanu)

---

Top Contributors

[![aocneanu](https://avatars.githubusercontent.com/u/16073274?v=4)](https://github.com/aocneanu "aocneanu (77 commits)")[![gandesc](https://avatars.githubusercontent.com/u/14071925?v=4)](https://github.com/gandesc "gandesc (23 commits)")[![raftx24](https://avatars.githubusercontent.com/u/10864136?v=4)](https://github.com/raftx24 "raftx24 (13 commits)")[![vmcvlad](https://avatars.githubusercontent.com/u/37445394?v=4)](https://github.com/vmcvlad "vmcvlad (6 commits)")[![DevIonut](https://avatars.githubusercontent.com/u/19207797?v=4)](https://github.com/DevIonut "DevIonut (3 commits)")[![AbdullahiAbdulkabir](https://avatars.githubusercontent.com/u/33360580?v=4)](https://github.com/AbdullahiAbdulkabir "AbdullahiAbdulkabir (3 commits)")[![GITmanuela](https://avatars.githubusercontent.com/u/44998004?v=4)](https://github.com/GITmanuela "GITmanuela (2 commits)")[![codacy-badger](https://avatars.githubusercontent.com/u/23704769?v=4)](https://github.com/codacy-badger "codacy-badger (1 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

cachecachedmodellaravellaravel-cachelaravel-ensolaravel-packagetraitmodel-cachelaravel-cachelaravel-ensorememberable

### Embed Badge

![Health badge](/badges/laravel-enso-rememberable/health.svg)

```
[![Health](https://phpackages.com/badges/laravel-enso-rememberable/health.svg)](https://phpackages.com/packages/laravel-enso-rememberable)
```

###  Alternatives

[imanghafoori/laravel-widgetize

A minimal yet powerful package to give a better structure and caching opportunity for your Laravel apps.

910140.9k12](/packages/imanghafoori-laravel-widgetize)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3416.9k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

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