PHPackages                             ryangjchandler/blade-cache-directive - 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. ryangjchandler/blade-cache-directive

ActiveLibrary[Caching](/categories/caching)

ryangjchandler/blade-cache-directive
====================================

Cache chunks of your Blade markup with ease.

v1.1.1(2mo ago)202200.8k—8.9%20[1 PRs](https://github.com/ryangjchandler/blade-cache-directive/pulls)1MITPHPPHP ^8.2CI failing

Since May 22Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/ryangjchandler/blade-cache-directive)[ Packagist](https://packagist.org/packages/ryangjchandler/blade-cache-directive)[ Docs](https://github.com/ryangjchandler/blade-cache-directive)[ GitHub Sponsors](https://github.com/ryangjchandler)[ RSS](/packages/ryangjchandler-blade-cache-directive/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (18)Versions (10)Used By (1)

Blade Cache Directive
=====================

[](#blade-cache-directive)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ce3785c68e5ec13f2daf520532ae6351fd9b36c73988f4b785ea039423510c36/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7279616e676a6368616e646c65722f626c6164652d63616368652d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryangjchandler/blade-cache-directive)[![Total Downloads](https://camo.githubusercontent.com/3842849b00127ce76be159df7a264699aab983f7838b8235ffe5bd87f3ac5a9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7279616e676a6368616e646c65722f626c6164652d63616368652d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ryangjchandler/blade-cache-directive)

Cache chunks of your Blade markup with ease.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require ryangjchandler/blade-cache-directive
```

You can publish the config file with:

```
php artisan vendor:publish --provider="RyanChandler\BladeCacheDirective\BladeCacheDirectiveServiceProvider" --tag="blade-cache-directive-config"
```

This is the contents of the published config file:

```
return [

    'enabled' => env('BLADE_CACHE_DIRECTIVE_ENABLED', true),

    'ttl' => env('BLADE_CACHE_DIRECTIVE_TTL', 3600),

];
```

Usage
-----

[](#usage)

This package adds a new `@cache` Blade directive. It accepts 2 arguments - the cache key and a TTL.

```
@cache('current_time', 30)
    {{ now() }}
@endcache
```

When used inside of a Blade template, the content between the 2 directives will be cached using Laravel's application cache. If a TTL (in seconds) isn't provided, the default TTL of **1 hour** will be used instead.

If you want to cache the content for a particular model, i.e. a `User` model, you can use string interpolation to change the key.

```
@cache("user_profile_{$user->id}")
    {{ $user->name }}
@endcache
```

When a new user is passed to this view, a separate cache entry will be created.

### Disabling caching

[](#disabling-caching)

If you wish to disable caching when using the `@cache` directive (useful for local development and testing), you can set the `BLADE_CACHE_DIRECTIVE_ENABLED` environment variable to `false`.

Alternatively, publish the configuration file and modify the `enabled` entry accordingly.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Ryan Chandler](https://github.com/ryangjchandler)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance88

Actively maintained with recent releases

Popularity52

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 63.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~220 days

Recently: every ~281 days

Total

9

Last Release

60d ago

Major Versions

v0.4.0 → v1.0.02024-03-13

PHP version history (2 changes)v0.1.0PHP ^8.0

v1.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/568d485d441c691b0358b9091254a6a671fef8f76b73f28af1180ad568d142b2?d=identicon)[ryangjchandler](/maintainers/ryangjchandler)

---

Top Contributors

[![ryangjchandler](https://avatars.githubusercontent.com/u/41837763?v=4)](https://github.com/ryangjchandler "ryangjchandler (21 commits)")[![phpfour](https://avatars.githubusercontent.com/u/171715?v=4)](https://github.com/phpfour "phpfour (4 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![applyACS](https://avatars.githubusercontent.com/u/13115651?v=4)](https://github.com/applyACS "applyACS (2 commits)")[![BrandonOldenhof](https://avatars.githubusercontent.com/u/42144260?v=4)](https://github.com/BrandonOldenhof "BrandonOldenhof (1 commits)")[![bobclewell](https://avatars.githubusercontent.com/u/116818?v=4)](https://github.com/bobclewell "bobclewell (1 commits)")[![yvesdaxmaz](https://avatars.githubusercontent.com/u/7295614?v=4)](https://github.com/yvesdaxmaz "yvesdaxmaz (1 commits)")

---

Tags

laravelryangjchandlerblade-cache-directive

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ryangjchandler-blade-cache-directive/health.svg)

```
[![Health](https://phpackages.com/badges/ryangjchandler-blade-cache-directive/health.svg)](https://phpackages.com/packages/ryangjchandler-blade-cache-directive)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[ryangjchandler/laravel-cloudflare-turnstile

A simple package to help integrate Cloudflare Turnstile.

438896.6k2](/packages/ryangjchandler-laravel-cloudflare-turnstile)[ryangjchandler/blade-capture-directive

Create inline partials in your Blade templates with ease.

8222.2M12](/packages/ryangjchandler-blade-capture-directive)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[ryangjchandler/laravel-comments

A dead-simple comments package for Laravel.

22118.2k](/packages/ryangjchandler-laravel-comments)[innoge/laravel-policy-soft-cache

This package helps prevent performance problems with frequent Policy calls within your application lifecycle.

2356.9k](/packages/innoge-laravel-policy-soft-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
