New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

alecto1b/laravel-gate-cache

Add a per-request caching layer to Laravel's Gate
1,679
Install
composer require alecto1b/laravel-gate-cache
Latest Version:v3.10.0
PHP:^8.1
Laravel:10 – 13
License:MIT
Last Updated:Jul 22, 2026
Links: GitHub  ·  Packagist
Maintainer: Alecto1b

Laravel Gate Cache

Software License

Laravel Gate Cache adds a caching layer to Laravel's Gate. Within one application lifecycle, an authorization callback is evaluated once for each unique ability and argument combination; later identical checks reuse the result, including denied results.

Requirements

Package Laravel PHP
3.x (current) 10.x–13.x ^8.1

The compatibility suite covers Laravel 10 through 13 with their matching Orchestra Testbench versions. Laravel 13 is tested on PHP 8.3 and PHP 8.5.

Installation

Install the package with Composer:

composer require alecto1b/laravel-gate-cache:^3.10

Laravel auto-discovers GateCacheProvider, which replaces the standard Gate contract binding with GateCache.

Usage

Use Laravel authorization as usual; no package-specific API is required:

use Illuminate\Support\Facades\Gate;

if (Gate::allows('update', $post)) {
    // The first identical check evaluates the ability; later checks reuse it.
}

This is particularly useful when a view repeats the same checks:

@foreach ($posts as $post)
    @can('add-posts') Add @endcan
    @can('edit-posts', $post) Edit @endcan
    @can('delete-posts', $post) Delete @endcan
@endforeach

Abilities and arguments remain separate cache dimensions: a different ability or different argument produces a separate authorization evaluation. Arguments should have stable JSON representations because the existing cache-key format uses json_encode().

Lifecycle limitations

The Gate binding is a singleton in Laravel's application container. In a traditional Laravel HTTP lifecycle, that makes the cache request-local because the application container is rebuilt for each request.

If an environment reuses the same application container across requests or jobs, the cache can live for that longer container lifecycle. This package does not currently provide a worker reset hook and does not claim Octane or other long-running-worker isolation; validate and manage that lifecycle before using it in such an environment.

Attribution

This project is a maintained fork of rickselby/laravel-gate-cache, originally created by Rick Selby. The original Git history and author attribution are preserved.

License

This package is open-sourced software licensed under the MIT License.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

655,942,320 9,702
laravel/framework

The Laravel Framework.

617,629,957 34,997
laravel/tinker

Powerful REPL for the Laravel framework.

524,145,802 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

442,489,569 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

412,228,818 4,664

Version History

Version Released PHP Laravel License
v3.10.0 ^8.1 ^10.0 || ^11.0 || ^12.0 || ^13.0 MIT