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

ActiveLibrary[Caching](/categories/caching)

elfeffe/blade-cache-directive
=============================

Cache chunks of your Blade markup with ease.

1.0.7(1y ago)125MITPHPPHP ^8.3

Since Feb 13Pushed 1mo ago1 watchersCompare

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

READMEChangelogDependencies (8)Versions (2)Used By (0)

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

[](#blade-cache-directive)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e933914215d6f53960b576388e0bc2417037a745338d50cae8b69316e1a138e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c66656666652f626c6164652d63616368652d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elfeffe/blade-cache-directive)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a10b165240308d3d1be98f39f021d83376ef4adf120c735167fed2b5aea9b36a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f656c66656666652f626c6164652d63616368652d6469726563746976652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/elfeffe/blade-cache-directive/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d2c86d367bedeb68df61cb1fb2a9e63d45a976762575f3ee62f02d1fb8470257/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f656c66656666652f626c6164652d63616368652d6469726563746976652f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/elfeffe/blade-cache-directive/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c818a31aa66c17449613c3e5bec2b9da3daa60f52216dd1a0ed76856b6cdc606/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c66656666652f626c6164652d63616368652d6469726563746976652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elfeffe/blade-cache-directive)

Cache chunks of your Blade markup with ease.

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

[](#installation)

You can install the package via Composer:

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

You can publish the config file with:

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

This is the contents of the published config file:

```
return [
    'ttl' => 3_600,
];
```

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.

Tags
----

[](#tags)

The package also supports Laravel's cache tags. You can add tags to your cached content:

```
@cache('user_profile', null, ['users', 'profiles'])
    {{ $user->name }}
@endcache
```

This allows you to invalidate specific groups of cached content using Laravel's cache tag functionality:

```
Cache::tags(['users'])->flush();
```

Note that cache tags are only available when using cache drivers that support tagging (Redis, Memcached).

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)

- [Federico Reggiani](https://github.com/elfeffe)
- [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

37

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

459d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/314f3009dfa2bbeec5895253f11aeba7246e3aa8b0cd1346b5015ef15cb8f773?d=identicon)[elfeffe](/maintainers/elfeffe)

---

Top Contributors

[![elfeffe](https://avatars.githubusercontent.com/u/4717507?v=4)](https://github.com/elfeffe "elfeffe (4 commits)")

---

Tags

laravelblade-cache-directiveElfeffe

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/elfeffe-blade-cache-directive/health.svg)](https://phpackages.com/packages/elfeffe-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/blade-cache-directive

Cache chunks of your Blade markup with ease.

202200.8k2](/packages/ryangjchandler-blade-cache-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)[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)[namoshek/laravel-redis-sentinel

An extension of Laravels Redis driver which supports connecting to a Redis master through Redis Sentinel.

38679.0k](/packages/namoshek-laravel-redis-sentinel)[dragon-code/laravel-cache

An improved interface for working with cache

6844.8k10](/packages/dragon-code-laravel-cache)

PHPackages © 2026

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