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(3mo ago)2565.8k↑25.6%6MITPHPPHP ^8.1CI failing

Since Nov 2Pushed 3mo 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 2d 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

53

—

FairBetter than 96% of packages

Maintenance78

Regular maintenance activity

Popularity42

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity63

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

115d 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-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.8k3](/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)
