tabuna/memento

Easy cache store for only stores the result within a single request or job

3.0.0 2023-05-18 02:24 UTC

This package is auto-updated.

Last update: 2024-12-04 14:50:07 UTC


README

Tests

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.