Skip to content

Memento is a small function that stores cache only within a single request or job.

License

Notifications You must be signed in to change notification settings

esplora/memento

Repository files navigation

Memento Memento

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.

About

Memento is a small function that stores cache only within a single request or job.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages