PHPackages                             berthott/laravel-api-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. berthott/laravel-api-cache

ActiveLibrary[Caching](/categories/caching)

berthott/laravel-api-cache
==========================

Laravel Helper for Caching API Responses

3.0.9(1y ago)01.1k↓83.3%1MITPHP

Since Dec 15Pushed 1y ago2 watchersCompare

[ Source](https://github.com/berthott/laravel-api-cache)[ Packagist](https://packagist.org/packages/berthott/laravel-api-cache)[ RSS](/packages/berthott-laravel-api-cache/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (2)Versions (17)Used By (1)

[![test workflow](https://github.com/berthott/laravel-api-cache/actions/workflows/test.yml/badge.svg)](https://github.com/berthott/laravel-api-cache/actions/workflows/test.yml/badge.svg)

Laravel-API-Cache
=================

[](#laravel-api-cache)

A helper for caching complete API Responses. Easily cache the complete response of you Laravel API.

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

[](#installation)

```
$ composer require berthott/laravel-api-cache
```

Usage
-----

[](#usage)

- The package automatically caches all responses to GET requests when installed and enabled.
    - The package assumes, that your routes are named according to Laravels Route::apiResource helper (`tablename.method`).
    - Responses are grouped via the table name (more specifically the first part of the route name, so custom route names are supported too).
- To automatically flush the cache corresponding to your model add the `FlushesApiCache` Trait to your model.
    - This will flush the cache for any model creation, update or deletion.
    - To also flush dependent models override the Traits `cacheDependencies` method and return a list of related route names.
- A `FlushApiCache` event listener is available to be connected with custom model events.

Options
-------

[](#options)

To change the default options use

```
$ php artisan vendor:publish --provider="berthott\ApiCache\ApiCacheServiceProvider" --tag="config"
```

- `enabled`: Enable the API caching. Default to `env('CACHE_API', false)`.
- `ignoreRoutes`: An array of route names to be ignored from the cache. Defaults to `[]`.
- `lifetime`: The lifetime of the cache in days. Defaults to `14`.
- `key`: A key to add to each redis cache to be able to use a single redis server and avoid name clashes. Defaults to`env('CACHE_API_KEY', env('APP_NAME', 'laravel'))`.

Architecture
------------

[](#architecture)

- The actual caching is done in `ApiCacheService`
- A store-key is used to connect requests / cached responses to a specific model / entity
- An `ApiCacheMiddleware` intercepts all http requests and calls `ApiCacheService`
- The `FlushesApiCache` trait observes creating / updating / deleting models and will clear the cache for the corresponding store

Compatibility
-------------

[](#compatibility)

Tested with Laravel 10.x.

License
-------

[](#license)

See [License File](license.md). Copyright © 2023 Jan Bladt.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

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

Every ~69 days

Recently: every ~81 days

Total

16

Last Release

616d ago

Major Versions

1.0.2 → 2.0.02022-03-23

2.0.2 → 3.0.02023-02-16

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3034025?v=4)[Jan Bladt](/maintainers/berthott)[@berthott](https://github.com/berthott)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/berthott-laravel-api-cache/health.svg)

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

###  Alternatives

[barryvdh/laravel-httpcache

HttpCache for Laravel

502404.4k10](/packages/barryvdh-laravel-httpcache)

PHPackages © 2026

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