esplora / memento
Easy cache store for only stores the result within a single request or job
Installs: 240 865
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- laravel/framework: ^10.0
Requires (Dev)
- orchestra/testbench-core: ^8.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-12-04 14:29:35 UTC
README
Memento is a small package that stores the result of a function or operation within a single HTTP request or job.
The package adds a new cache stored in the container instance, which avoids the need to use a Laravel Cache with access to the file system or fast storage like Redis when the result only needs to be stored for a short time.
Installation
You can install Memento in your project using the Composer package manager:
composer require esplora/memento
Usage
The simplest way to use Memento is with the provided helper function:
memento('users', function() { return DB::table('users')->get(); });
This function will return the result of the provided closure on the first call, and any subsequent calls within the same HTTP request or job will return the same result. The cache will be automatically flushed after the request or job is completed.
Flushing the Cache
To flush the entire Memento cache, you can use the following code:
use Esplora\Memento\Memento; Memento::flush();
License
The MIT License (MIT). Please see License File for more information.