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.
You can install Memento in your project using the Composer package manager:
composer require esplora/memento
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.
To flush the entire Memento cache, you can use the following code:
use Esplora\Memento\Memento;
Memento::flush();
The MIT License (MIT). Please see License File for more information.