Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ghabriel25's avatar

How to test Cache memoization

Hi, I really need any information about how to create performance test only for Cache memoization.

Before

Cache::remember('posts', 60, function () {
    return Post::all();
});

After

Cache::memo()->remember('posts', 60, function () {
    return Post::all();
});

I'm not familiar with the flow behind cache memoization so I have no idea what should be considered when do performance testing.

0 likes
1 reply
JussiMannisto's avatar

If you want to run performance benchmarks, Laravel has utilities for it:

https://laravel.com/docs/13.x/helpers#benchmarking

Cache::memo() stores retrieved values in memory so that the underlying cache store is only hit once per record per request. It'll only have an effect if you try to fetch the same record multiple times in a single request.

You might see a big difference in the benchmarks if you crank up the number of iterations, but that's probably misleading. There might be no real performance benefit in practice.

Please or to participate in this conversation.