Download the PHP package alielmajdaoui/laravel-memoize without Composer
On this page you can find all versions of the php package alielmajdaoui/laravel-memoize. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alielmajdaoui/laravel-memoize
More information about alielmajdaoui/laravel-memoize
Files in alielmajdaoui/laravel-memoize
Package laravel-memoize
Short Description Memoize your expensive computed values to use in different components per each request.
License MIT
Informations about the package laravel-memoize
Laravel Memoize
Memoize your expensive computed values to use in different components per each request.
Use case
Suppose you have an AddCommentRequest
class whose job is to validate comments being added to your blog posts.
During the validation, you might need to make a database query using an Eloquent model or directly using the DB
facade, and the same query result might be needed in the near future in another app component, say in your CommentController
where this Request class is being called(injected) from.
If you do the same query from those 2 different places, you will end up with duplicate queries, and here where laravel-memoize
comes to the rescue. It's to simple, just wrap the query in a \Closure
and it will be memoized for you.
Installation
Install with composer
Usage
You can memoize a heavy computed value by using the method remember(string $key, \Closure $callback)
from Aliem\Memoize\Facades\Memoize
facade.
Example
remember(string $key, \Closure $callback): mixed
Check if the item is memoized, or it will execute the \Closure
and memoize the result.
Example
get(string $key): mixed
Get a memoized item
Example
put(string $key, mixed $value): void
Memoize an item
has(string $key): bool
Check if an item is memoized
forget(string $key): bool
Delete a memoized item.
Memoize::flush()
Delete all memoized items
License
MIT.