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)126MITPHPPHP ^8.3

Since Feb 13Pushed 3mo 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 today

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

35

—

LowBetter than 77% of packages

Maintenance63

Regular maintenance activity

Popularity9

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

504d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4717507?v=4)[federeggiani](/maintainers/elfeffe)[@elfeffe](https://github.com/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-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.3k3](/packages/defstudio-telegraph)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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