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(5mo ago)205241.3k↓43.3%21[1 PRs](https://github.com/ryangjchandler/blade-cache-directive/pulls)1MITPHPPHP ^8.2CI failing

Since May 22Pushed 5mo 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 2w 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

60

—

FairBetter than 98% of packages

Maintenance73

Regular maintenance activity

Popularity53

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity71

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

151d 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-permission

Permission handling for Laravel 12 and up

13.0k107.5M1.6k](/packages/spatie-laravel-permission)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.2k12.6M140](/packages/dedoc-scramble)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3915.5k](/packages/rawilk-profile-filament-plugin)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

46273.9k](/packages/harris21-laravel-fuse)[vormkracht10/laravel-mails

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

25060.1k](/packages/vormkracht10-laravel-mails)[elegantly/laravel-translator

All on one translations management for Laravel

6339.5k](/packages/elegantly-laravel-translator)

PHPackages © 2026

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