PHPackages                             sinemacula/laravel-cached-crypt - 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. sinemacula/laravel-cached-crypt

AbandonedLibrary[Caching](/categories/caching)

sinemacula/laravel-cached-crypt
===============================

A Laravel package that adds transparent caching to decrypted values for improved performance across encrypted attributes.

v1.3.1(3mo ago)015.3k—2.4%1[1 PRs](https://github.com/sinemacula/laravel-cached-crypt/pulls)Apache-2.0PHPPHP ^8.3CI passing

Since May 25Pushed 1mo agoCompare

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

READMEChangelog (4)Dependencies (29)Versions (12)Used By (0)

Laravel Cached Crypt
====================

[](#laravel-cached-crypt)

> 📦 **This package is archived and no longer maintained.**The problem it set out to solve - repeated in-request decryption overhead - turns out to be a very narrow one in practice. Modern AES decryption is extremely fast, and where repeated decryption is genuinely measurable it is better handled at the application layer (caching the resolved value on the model or behind a dedicated accessor) than by globally swapping the framework encrypter. The optional cross-request plaintext caching also carried security trade-offs that we no longer consider justified by the marginal gains.
>
> Existing tagged releases (up to `v1.3.1`) remain installable via Composer/Packagist, but the repository is read-only and will receive no further updates, including for new Laravel versions. We recommend relying on Laravel's built-in encryption directly.

[![Latest Stable Version](https://camo.githubusercontent.com/04b03ea4d193f0e63de69a5132c4e169351078b5913abfa0af35f24e33cc484e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73696e656d6163756c612f6c61726176656c2d6361636865642d63727970742e737667)](https://packagist.org/packages/sinemacula/laravel-cached-crypt)[![Build Status](https://github.com/sinemacula/laravel-cached-crypt/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/sinemacula/laravel-cached-crypt/actions/workflows/tests.yml)[![StyleCI](https://camo.githubusercontent.com/1919ab39f7ee6869019d819e19e2e84237b3c9bb6c09adde78d991eee9cfb56b/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3938393832343238302f736869656c643f7374796c653d666c6174266272616e63683d6d6173746572)](https://github.styleci.io/repos/989824280)[![Maintainability](https://camo.githubusercontent.com/601a07007b73f6d804a144d4357d6797ee42c6ba5c6bc07cf3a9a706f2107919/68747470733a2f2f716c74792e73682f6261646765732f33386265323033612d393333622d346165382d396538302d6636653866393234656362392f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/sinemacula/projects/laravel-cached-crypt)[![Code Coverage](https://camo.githubusercontent.com/2acc3e663faa3adf1f12507b6105a75b51298090b70b3f6e3ba4f6f223a4877f/68747470733a2f2f716c74792e73682f6261646765732f33386265323033612d393333622d346165382d396538302d6636653866393234656362392f746573745f636f7665726167652e737667)](https://qlty.sh/gh/sinemacula/projects/laravel-cached-crypt)[![Total Downloads](https://camo.githubusercontent.com/3175ca8a22f277b39a1f0928d73c74da7de0c8d05eff04d64cb988d09aea460f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73696e656d6163756c612f6c61726176656c2d6361636865642d63727970742e737667)](https://packagist.org/packages/sinemacula/laravel-cached-crypt)

Laravel Cached Crypt wraps Laravel's encrypter to reduce repeated decrypt overhead in hot paths. It is drop-in by default, memoizes decrypt results in-process, and can optionally persist plaintext with bounded TTL, epoch versioning, and size guardrails.

> ⚠️ **Security Warning**Persisted plaintext caching should only be enabled when operational controls are in place. Use secured Redis/Memcached with encryption in transit and at rest, private networking, and short TTLs. Prefer memo-only mode unless cross-request reuse is required.

Features
--------

[](#features)

- Drop-in provider integration with no manual registration order requirements
- Enabled-by-default memo-only optimization path (`enabled=true`, `memo_only=true`, `cache_plaintext=false`)
- Optional cross-request plaintext persistence with TTL (no `rememberForever`)
- Epoch and optional key fingerprint namespacing for safe invalidation boundaries
- SHA-256 payload hashing for cache keys
- Optional dedicated cache store and optional cache tagging
- Size guardrails (`min_bytes_to_cache`, `max_memo_bytes`, `max_bytes_to_cache`)
- Optional eligibility resolver hook for app-specific persistence decisions
- Fail-open behavior for cache backend and resolver failures (decrypt path preserved)
- Optional sampled metric logging for cache/decrypt behavior

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

[](#installation)

```
composer require sinemacula/laravel-cached-crypt
```

Laravel will automatically register the service provider via package discovery. No manual provider ordering is required.

Configuration
-------------

[](#configuration)

Publish the config file:

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

Default configuration in `config/cached-crypt.php`:

```
return [
    'enabled' => true,
    'cache_plaintext' => false,
    'memo_only' => true,
    'ttl_seconds' => 120,
    'epoch' => 'v1',
    'key_fingerprint' => null,
    'store' => null,
    'min_bytes_to_cache' => 1024,
    'max_memo_bytes' => 262144,
    'max_bytes_to_cache' => 262144,
    'use_tags' => false,
    'eligibility_resolver' => null,
    'metrics' => [
        'enabled' => false,
        'sample_rate' => 0.10,
    ],
];
```

Safe defaults:

- Works out of the box with no additional env vars
- Package enabled in memo-only mode by default
- Cross-request plaintext persistence remains off unless explicitly enabled

How It Works
------------

[](#how-it-works)

For each decrypt call:

1. Build a namespaced key with epoch and SHA-256 payload hash.
2. Read from in-process memoization cache first.
3. Optionally read/write persistent plaintext cache when enabled and eligible.
4. Decrypt via Laravel when needed, then memoize and optionally persist.
5. Fail open on cache/resolver errors so decrypt behavior is preserved.

Persistent writes are bounded by:

- `ttl_seconds`
- `min_bytes_to_cache` (encrypted payload size)
- `max_memo_bytes` (in-process memo value size estimate)
- `max_bytes_to_cache` (decrypted value size estimate)
- Optional resolver callback (`eligibility_resolver`)

Operating Modes
---------------

[](#operating-modes)

- `memo_only = true`: in-process reuse only, no cross-request plaintext persistence.
- `cache_plaintext = true` and `memo_only = false`: allows persistent plaintext caching with guardrails.

Key Rotation and Invalidation
-----------------------------

[](#key-rotation-and-invalidation)

When encryption settings change (for example `APP_KEY`, cipher, or `previous_keys`), bump `epoch`. This immediately cold-starts cached plaintext keys without requiring global cache flushes.

If `use_tags` is enabled and the store supports tags, entries are grouped under:

- `cached-crypt`
- `cached-crypt:{epoch}`

Metrics
-------

[](#metrics)

When `metrics.enabled` is true, sampled events are logged with:

- cache hit/miss source (`memo` or `persistent`)
- decrypt duration in milliseconds
- approximate bytes persisted for cache writes
- cache error events for persistent read/write failures

Testing
-------

[](#testing)

```
composer test
composer test-coverage
composer check
```

Contributing
------------

[](#contributing)

Contributions are welcome via GitHub pull requests.

Security
--------

[](#security)

If you discover a security issue, please contact Sine Macula directly rather than opening a public issue.

License
-------

[](#license)

Licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance88

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92% 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 ~105 days

Total

4

Last Release

90d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6262ea965c244b0c946a2f29a94da05e30846c066a0b59399466216654c78fe6?d=identicon)[sinemacula](/maintainers/sinemacula)

---

Top Contributors

[![sinemacula-ben](https://avatars.githubusercontent.com/u/118753672?v=4)](https://github.com/sinemacula-ben "sinemacula-ben (23 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![derrickschoen](https://avatars.githubusercontent.com/u/13784912?v=4)](https://github.com/derrickschoen "derrickschoen (1 commits)")

---

Tags

laravelencryptioncachesine macula

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sinemacula-laravel-cached-crypt/health.svg)

```
[![Health](https://phpackages.com/badges/sinemacula-laravel-cached-crypt/health.svg)](https://phpackages.com/packages/sinemacula-laravel-cached-crypt)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

973172.3k2](/packages/awssat-laravel-visits)[nexxai/laravel-cfcache

A handful of Cloudflare cache helpers for Laravel

13314.7k](/packages/nexxai-laravel-cfcache)[dragon-code/laravel-cache

An improved interface for working with cache

7046.0k10](/packages/dragon-code-laravel-cache)

PHPackages © 2026

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