ryangjchandler/blade-cache-directive
A lightweight Laravel package that adds an @cache Blade directive, letting you cache rendered fragments of views—partials, loops, or expensive blocks—with a TTL and optional key. Drop it into existing templates to cut rendering time without extra setup.
ryangjchandler/blade-cache-directive is a micro-package that adds a @cache Blade directive (and a matching @endcache) to cache rendered template fragments. It is a single-purpose utility: it does not introduce a new caching backend, a service provider graph, or a data layer. Architecturally it is a thin ergonomic wrapper around Laravel's existing Cache facade, invoked at template render time.
Architecture fit. It fits cleanly wherever the application already uses the framework cache. There is no new infrastructure, no queue, no external service. The only architectural coupling is to Laravel's cache repository contract and to Blade compilation. For teams already comfortable with Cache::remember() in view composers or @php blocks, this is a readability improvement rather than a capability change.
Integration feasibility. Very high. A single composer require, no published config in the release notes, no migration, no service provider registration expected beyond package discovery. The v1.1.1 change is a composer constraint widening for Laravel 13.x — no runtime behavior change, no API change, no deprecation. Any application currently on Laravel 10/11/12 and PHP 8.x can adopt it in an afternoon.
Technical risk. Low in the abstract, but not zero, and the risks are the "silent correctness" kind rather than the "it won't boot" kind. Three stand out:
@cache assuming tag-based invalidation will discover at the worst possible moment that their only lever is TTL. Redis/Memcached are effectively required for anything with meaningful invalidation needs.composer.json before that major is stable is a reasonable forward-compatibility posture, but it means composer update can pull a combination that has never been executed.Key questions for the maintainer / for our own review:
Cache::forget on model events)?Stack fit. Excellent for a standard Laravel monolith or modular monolith on PHP 8.2+ where Blade is the rendering layer and the cache store is Redis or Memcached. Poor fit for API-only services (no Blade), for applications that have standardized on view composers plus Cache::remember (the package adds a second idiom for the same job), and for multi-tenant systems with heavy per-tenant cache partitioning unless key conventions are already established.
Migration path. There is nothing to migrate. Adoption is additive:
@php ... Cache::remember(...) ... @endphp to @cache(...).If the team later wants to remove it, the reversal is mechanical: inline the Cache::remember call. There is no data migration, no schema, no lock-in beyond a small amount of template churn.
Compatibility. Requires a Laravel version within the package's constraint (now including 13.x) and an appropriate PHP version. The real compatibility question is the cache driver, not the framework: confirm the production store supports the invalidation strategy chosen (tags require Redis/Memcached).
Sequencing.
@cache usage; confirm the CI pipeline covers the Laravel version(s) actually deployed.Maintenance. Negligible ongoing effort for the consuming team — the package is small, has no configuration surface to drift, and no scheduled jobs. The maintenance burden sits with the upstream maintainer, and that is where the genuine concern lies: a single-author package with a narrow user base. If it goes unmaintained, the fallback is a ~30-line replacement, so the exit cost is low. That materially reduces the strategic risk compared to, say, a single-author package that owns a persistence layer.
Support. Internal support load should be near zero if the guardrails above are in place. The likely support tickets are not "the package is broken" but "why is this page showing yesterday's pricing" — i.e., cache correctness incidents that would have occurred with hand-rolled caching too.
Scaling. The package itself does not scale; the cache store does. Caching fragment output reduces database and CPU load roughly in proportion to hit rate, which is the point. Watch for two second-order effects: Redis memory growth from large cached HTML blobs (consider compressing or shortening TTL), and cache stampede when a popular fragment expires under load — the directive does not appear to provide probabilistic early expiration or locking, so high-traffic fragments need jittered TTLs or a warm-up path.
Failure modes.
array driver in an environment) — caching appears to work, provides no benefit, and hides the problem until load testing.composer update proceed into an untested combination. Pin explicitly in CI.Ramp-up. Hours, not days. A mid-level Laravel developer will read the README and be productive immediately. The non-obvious learning is entirely about cache key design and invalidation, which is framework knowledge rather than package knowledge.
Verdict. v1.1.1 is a maintenance release — a forward-looking compatibility constraint, no behavioral change, no breaking change, no deprecation. It does not alter the package's risk profile. The package is a reasonable, low-commitment convenience for teams doing fragment caching in Blade, provided the team owns key-naming conventions and does not assume tag support. It is not load-bearing infrastructure, and it should not be treated as such. Recommend adoption for non-personalized fragments, with the guardrails above, and no action required as a result of this specific release beyond confirming that our CI matrix matches the Laravel version we actually deploy.
How can I help you explore Laravel packages today?