sinemacula / laravel-cached-crypt
A Laravel package that adds transparent caching to decrypted values for improved performance across encrypted attributes.
Requires
- php: ^8.3
- illuminate/encryption: *
- illuminate/support: *
Requires (Dev)
- laravel/framework: *
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2025-05-25 04:23:15 UTC
README
⚠️ Security Warning
This package caches decrypted values using Laravel's configured cache driver. You should only use this package with a cache store that provides encryption at rest, such as Redis or Memcached in a secured environment. Do not use this with insecure cache drivers likefile
orarray
, as decrypted data will be stored in plaintext on disk or in memory.
Laravel Cached Crypt is a zero-configuration package that transparently adds caching to Laravel’s Crypt facade, reducing CPU load by avoiding repeated decryption of encrypted values across your application.
Features
- Transparent Integration: Automatically replaces Laravel's default
Crypt
implementation—no configuration or code changes required. - Cached Decryption: Caches decrypted values using Laravel's default cache driver (e.g. Redis) to improve performance on read-heavy encrypted fields.
- Deployment-Friendly: Works seamlessly with deploy-based cache flushing strategies to keep cache fresh and consistent.
Installation
To install Laravel Cached Crypt, run the following command in your project directory:
composer require sinemacula/laravel-cached-crypt
Laravel will automatically register the service provider via package discovery.
Configuration
This package requires no configuration. Once installed, it will automatically override Laravel’s default Crypt
binding
and begin caching decrypted values across your application.
How It Works
Laravel Cached Crypt intercepts calls to Crypt::decryptString()
and caches the decrypted output using a hash of the
encrypted payload. On subsequent calls, it retrieves the decrypted value from cache rather than reprocessing the
decryption.
This approach is especially effective for:
- APIs that return encrypted model attributes in large datasets
- Applications with frequent reads from encrypted fields
- Reducing CPU load and PHP-FPM worker saturation under high concurrency
Security Considerations
Decrypted values are stored in your application’s configured cache store. Ensure that your cache backend (e.g. Redis) is properly secured, resides within a private network or VPC, and uses encryption in transit. This package does not alter Laravel’s encryption algorithms or key handling in any way.
Contributing
Contributions are welcome and will be fully credited. We accept contributions via pull requests on GitHub.
Security
If you discover any security-related issues, please email instead of using the issue tracker.
License
Laravel Cached Crypt is open-sourced software licensed under the Apache License, Version 2.0.