PHPackages                             alielmajdaoui/laravel-memoize - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. alielmajdaoui/laravel-memoize

ActiveLibrary[Caching](/categories/caching)

alielmajdaoui/laravel-memoize
=============================

Memoize your expensive computed values to use in different components per each request.

0.0.1(5y ago)264MITPHPPHP ^7.2.5|^8.0

Since Mar 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/alielmajdaoui/laravel-memoize)[ Packagist](https://packagist.org/packages/alielmajdaoui/laravel-memoize)[ RSS](/packages/alielmajdaoui-laravel-memoize/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Laravel Memoize
===============

[](#laravel-memoize)

Memoize your expensive computed values to use in different components per each request.

Use case
--------

[](#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
============

[](#installation)

Install with composer

```
composer require aliem/laravel-memoize
```

Usage
=====

[](#usage)

You can memoize a heavy computed value by using the method `remember(string $key, \Closure $callback)` from `Aliem\Memoize\Facades\Memoize` facade.

Example
-------

[](#example)

```
