PHPackages                             innoge/laravel-policy-soft-cache - 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. innoge/laravel-policy-soft-cache

ActiveLibrary[Caching](/categories/caching)

innoge/laravel-policy-soft-cache
================================

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

1.6.0(2mo ago)2356.9k—8.7%6MITPHPPHP ^8.1CI passing

Since Nov 2Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/InnoGE/laravel-policy-soft-cache)[ Packagist](https://packagist.org/packages/innoge/laravel-policy-soft-cache)[ Docs](https://github.com/innoge/laravel-policy-soft-cache)[ RSS](/packages/innoge-laravel-policy-soft-cache/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (15)Used By (0)

Laravel Policy Soft Cache Package
=================================

[](#laravel-policy-soft-cache-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f9b5f4266331d4f179a51141d93d7db289b8b457b96bd77c930f45c91986d3c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e6e6f67652f6c61726176656c2d706f6c6963792d736f66742d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/innoge/laravel-policy-soft-cache)[![Tests](https://github.com/InnoGE/laravel-policy-soft-cache/actions/workflows/run-tests.yml/badge.svg)](https://github.com/InnoGE/laravel-policy-soft-cache/actions/workflows/run-tests.yml)[![Fix PHP code style issues](https://github.com/InnoGE/laravel-policy-soft-cache/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/InnoGE/laravel-policy-soft-cache/actions/workflows/fix-php-code-style-issues.yml)[![Total Downloads](https://camo.githubusercontent.com/68cc737bc2a38fd4f7a821484d29d188f9b29c032289d4689d03ec7753f8077b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e6e6f67652f6c61726176656c2d706f6c6963792d736f66742d63616368652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/innoge/laravel-policy-soft-cache)

Optimize your Laravel application's performance with soft caching for policy checks. This package caches policy invocations to prevent redundant checks within the same request lifecycle, enhancing your application's response times.

Requirements
------------

[](#requirements)

This package is compatible with `Laravel 9, 10, 11, 12, 13`, and PHP &gt;= 8.1.

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

[](#installation)

You can install the package via composer:

```
composer require innoge/laravel-policy-soft-cache
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Innoge\LaravelPolicySoftCache\LaravelPolicySoftCacheServiceProvider"
```

This is the contents of the published config file:

```
return [
    /*
     * When enabled, the package will cache the results of all Policies in your Laravel application
     */
    'cache_all_policies' => env('CACHE_ALL_POLICIES', true),
];
```

You can also use `CACHE_ALL_POLICIES` in your `.env` file to change it.

```
CACHE_ALL_POLICIES=false

```

Usage
-----

[](#usage)

By default, this package caches all policy calls of your entire application. You can disable this behavior by setting the `cache_all_policies`configuration to false. Now you can specify which Policy classes should be soft cached and which not. If you want your policy to be cached, add the `Innoge\LaravelPolicySoftCache\Contracts\SoftCacheable` interface.

For Example:

```
use Innoge\LaravelPolicySoftCache\Contracts\SoftCacheable;

class UserPolicy implements SoftCacheable
{
    ...
}

```

Clearing the cache
------------------

[](#clearing-the-cache)

Sometimes you want to clear the policy cache after model changes. You can call the `Innoge\LaravelPolicySoftCache::flushCache();` method.

Known Issues
------------

[](#known-issues)

### Gate::before and Service Provider Load Order

[](#gatebefore-and-service-provider-load-order)

When the `innoge/laravel-policy-soft-cache` package is installed in an application that utilizes `Gate::before`, typically defined in the `AuthServiceProvider`, a conflict may arise due to the order in which service providers are loaded.

#### Resolution Steps

[](#resolution-steps)

To resolve this issue, follow these steps:

1. **Manual Service Provider Registration**: Add `\Innoge\LaravelPolicySoftCache\LaravelPolicySoftCacheServiceProvider::class` to the end of the `providers` array in your `config/app.php`. This manual registration ensures that the `LaravelPolicySoftCacheServiceProvider` loads after all other service providers, including `AuthServiceProvider`.

    ```
    'providers' => [
        // Other Service Providers

        \Innoge\LaravelPolicySoftCache\LaravelPolicySoftCacheServiceProvider::class,
    ],
    ```
2. **Disable Auto-Discovery for the Package**: To prevent Laravel's auto-discovery mechanism from automatically loading the service provider, add `innoge/laravel-policy-soft-cache` to the `dont-discover` array in your `composer.json`. This step is crucial for maintaining the manual load order.

    ```
    "extra": {
        "laravel": {
            "dont-discover": ["innoge/laravel-policy-soft-cache"]
        }
    },
    ```
3. **Reinstall Dependencies**: After updating your `composer.json`, run `composer install` to apply the changes. This step is necessary for the changes to take effect.

    ```
    composer install
    ```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

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

[](#security-vulnerabilities)

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

Credits
-------

[](#credits)

- [Tim Geisendörfer](https://github.com/geisi)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.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 ~111 days

Recently: every ~221 days

Total

12

Last Release

69d ago

Major Versions

0.1.1 → 1.0.02023-01-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/01edc74b3b6f2ecfe6106f68787500e5c46c51acc7fbe7aa04bb378c9190c79b?d=identicon)[geisi](/maintainers/geisi)

---

Top Contributors

[![geisi](https://avatars.githubusercontent.com/u/10728579?v=4)](https://github.com/geisi "geisi (31 commits)")[![bessone](https://avatars.githubusercontent.com/u/1089510?v=4)](https://github.com/bessone "bessone (1 commits)")[![Perer876](https://avatars.githubusercontent.com/u/70984218?v=4)](https://github.com/Perer876 "Perer876 (1 commits)")[![ruaq](https://avatars.githubusercontent.com/u/25234289?v=4)](https://github.com/ruaq "ruaq (1 commits)")[![vazaha-nl](https://avatars.githubusercontent.com/u/1075085?v=4)](https://github.com/vazaha-nl "vazaha-nl (1 commits)")

---

Tags

cachelaravelphppolicylaravelinnogelaravel-policy-soft-cache

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/innoge-laravel-policy-soft-cache/health.svg)

```
[![Health](https://phpackages.com/badges/innoge-laravel-policy-soft-cache/health.svg)](https://phpackages.com/packages/innoge-laravel-policy-soft-cache)
```

###  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)[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)[innoge/filament-form-faker

A package to generate fake input data for Filament forms.

162.5k](/packages/innoge-filament-form-faker)

PHPackages © 2026

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