Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Memoize Bundle

Memoize Bundle Laravel Package

rikudou/memoize-bundle

A Symfony bundle for memoizing expensive method calls. Add attributes to service methods to cache results and avoid repeated computation, improving performance with minimal code changes.

View on GitHub
Deep Wiki
Context7

Symfony bundle for class/method memoization

Frequently asked questions about Memoize Bundle
Can I use rikudou/memoize-bundle in a Laravel application?
No. rikudou/memoize-bundle is a Symfony bundle that registers through bundles.php and the Symfony DI container, and Laravel has no bundle registration hook or equivalent compiler-pass lifecycle, so it cannot be Composer-required into a Laravel app and used as-is. Laravel also already ships first-party equivalents such as the once() helper, Cache::remember(), Cache::flexible() and container singletons. Treat it as inspiration for an in-house implementation rather than a dependency.
How do I install rikudou/memoize-bundle in a Symfony project?
Install it with Composer using rikudou/memoize-bundle, then register the bundle in config/bundles.php as you would any Symfony bundle. Because it relies on autoconfiguration and service decoration, the #[Memoize] attribute is picked up automatically on your services. You configure the backing cache pool through the bundle configuration in your Symfony config files. There is no Laravel service provider or config/memoize.php equivalent.
How does the #[Memoize] attribute cache method calls?
You add the #[Memoize] attribute to a method on a Symfony service, and the bundle intercepts calls through service decoration. Results are cached per argument set, so identical arguments return the memoized value while distinct inputs stay isolated. This suits pure computations, configuration lookups, and repeated API or database reads within a request. It is not a general-purpose query cache and does not replace response or fragment caching.
Which Symfony and PHP versions does rikudou/memoize-bundle support?
Version 1.1.0 added Symfony 7 support, so Symfony 6.4 LTS and 7.x are both viable targets. The PHP 8.2 and 8.3 floors are the ones to verify. There is no Laravel version support at any release, and a changelog claim is not the same as a published CI matrix. Confirm the test suite actually runs against 7.0, 7.1 and 7.2 before you bank on it.
What is the cache key specifier added in v1.1.0?
Previously the cache key was derived implicitly by the framework from the method arguments, which could collide or misbehave for objects, arrays and closures. The key specifier lets you declare the key explicitly for a memoized method. It is a mitigation lever rather than a guarantee, because correctness now depends on engineers using it correctly and that is a code-review discipline issue. The release notes do not document key-derivation semantics, so you will need to read the source.
What are the Laravel-native alternatives to this Symfony memoize bundle?
Laravel has once() for per-request memoization of closures, Cache::remember() for explicit keyed caching, Cache::flexible() for stale-while-revalidate behaviour, and container singletons for shared instances. None of these are attribute-driven, but they cover the same use cases without a third-party dependency. If you want the attribute ergonomics, a small in-house attribute plus reflection wrapper is a build task, not an integration.
How do I disable memoization in test or development environments?
The bundle is designed to be easy to disable per environment through Symfony configuration. In tests, point it at an in-memory array cache pool and clear it between test cases so memoized values do not leak across assertions. Because caching happens inside the service decoration layer, you can also swap the decorated service for a plain implementation in the test container. There is no Laravel testing helper or facade fake for this package.
Is rikudou/memoize-bundle production-ready?
It is technically viable for a small Symfony service, but the risk profile is high and mostly supply-chain rather than technical. The project has roughly 22 stars, no known dependents, a bus factor of one, sparse documentation, and thin CI evidence. The v1.1.0 release notes are two bullet points with no migration guidance and no documented semantics for the new key specifier. Treat it as unproven in production and pin versions if you adopt it.
Does memoized data persist across requests or survive long-running workers?
That depends entirely on the configured cache pool: an in-memory pool scopes memoization to the current request or process, while a persistent pool keeps values across requests. Nothing in the v1.1.0 changes addresses lifecycle scope, TTL, invalidation, eviction, or memory growth in long-running workers such as Messenger or RoadRunner. You need to define those semantics yourself before choosing a persistent pool. In Laravel terms this maps to choosing between once() and Cache::remember() with an explicit TTL.
How would I replicate memoize-bundle behaviour in Laravel?
Lift the idea, not the code: a PHP 8 attribute plus a reflection-based wrapper, a container proxy, or middleware can intercept method calls and delegate to Cache::remember() with a derived or declared key. In most Laravel code a simpler once() or Cache::remember() call at the call site is cheaper than building interception infrastructure. If you do build it, copy the v1.1.0 cache key specifier ergonomics, since explicit keys are what keep object and array arguments from colliding. Budget it as a small internal package with its own tests, not a weekend helper.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib