PHPackages                             glaivepro/cachepage - 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. glaivepro/cachepage

ActiveLibrary[Caching](/categories/caching)

glaivepro/cachepage
===================

Laravel middleware for full page caching.

1.5.1(4y ago)146901MITPHPPHP &gt;=5.6.0

Since Oct 6Pushed 4y ago3 watchersCompare

[ Source](https://github.com/GlaivePro/CachePage)[ Packagist](https://packagist.org/packages/glaivepro/cachepage)[ Docs](https://github.com/GlaivePro/CachePage)[ RSS](/packages/glaivepro-cachepage/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (10)Used By (0)

CachePage
=========

[](#cachepage)

Laravel middleware for full page caching.

Table of Contents
-----------------

[](#table-of-contents)

- [How do I get this in my app?](#how-do-i-get-this-in-my-app)
    - [Composer](#composer)
    - [Binding it to your app](#binding-it-to-your-app)
- [How do I use it?](#how-do-i-use-it)
    - [Middleware](#middleware)
    - [User-specific caching](#user-specific-caching)
- [Other concerns](#other-concerns)
    - [Can I skip it?](#can-i-skip-it)
    - [How to clear the cache?](#how-to-clear-the-cache)
    - [When should I use it?](#when-should-i-use-it)
- [Changelog](#changelog)
- [License](#license)

How do I get this in my app?
----------------------------

[](#how-do-i-get-this-in-my-app)

```
$ composer require glaivepro/cachepage
```

### Binding it to your app

[](#binding-it-to-your-app)

> Skip this section if you are using package discovery which is default for recent versions of Laravel.

Firt of all you have to register the service provider.

Open `config/app.php` and find the `providers` key. Add this line to the array.

```
	...
	GlaivePro\CachePage\CachePageServiceProvider::class,
	...
```

If you will need to adjust the behaviour of the package, you have to publish the configuration file according to your application. Just execute this artisan command:

```
php artisan vendor:publish --provider="GlaivePro\CachePage\CachePageServiceProvider"

```

And you will have the `config/cachepage.php` file to change whenever this manual tells you to adjust something in the configuration.

How do I use it?
----------------

[](#how-do-i-use-it)

### Middleware

[](#middleware)

Add the `gpcachepage` middleware to a route and all responses will be cached for the configured time. By default it's 5 minutes, but you can change it in the configuration.

```
    Route::get('/', 'PageController@welcome')->middleware('gpcachepage');
```

The response will be cached using Laravels `Cache` functionality you should configure it. It will be keyed by requests url and tagged with `gpcachepage` tag (if your cache driver supports tagging).

You can specify time if you want to. For example, to cache a page for two minutes:

```
    Route::get('contacts', 'PageController@contacts')->middleware('gpcachepage:120');
```

Or make a group of routes that cache their responses for 5 minutes:

```
    Route::group(['middleware' => ['gpcachepage:300']], function () {
        Route::get('about', 'PageController@about');
        Route::get('policy', 'PageController@policy');
    });
```

For further advice regarding usage of middlewares you should read the [Laravel documentation about middlewares](https://laravel.com/docs/master/middleware).

### User-specific caching

[](#user-specific-caching)

Sometimes the page should be different for different users. For example, you might want to display the users name at top - you will want users to see their own name there, not the cached one, right?

You can do it like this:

```
    Route::get('contacts', 'PageController@contacts')->middleware('gpcachepage:120,id');
```

Specifying time in this case is unavoidable. The key for caching will be something like `id=153&url=http://mypage.com`.

If you want to key by users role or some other field (or related field), you can try to pass them like this:

```
	Route::get('contacts', 'PageController@contacts')->middleware('gpcachepage:120,role.name');
```

The middleware will then try to get a value from `Auth::user()->role->name`.

If you only want to cache pages for guests, use the key `NULL` like this and caching will be disabled for authenticated users:

```
    Route::get('contacts', 'PageController@contacts')->middleware('gpcachepage:120,NULL');
```

Other concerns
--------------

[](#other-concerns)

### Can I skip it?

[](#can-i-skip-it)

If you want to skip caching and just view a freshly made page, pass `skipcache=true` as a HTTP parameter, for example:

```
http://mypage.com/contacts?skipcache=true

```

You can also use `1` instead of `true` if you prefer it.

If you are afraid that users might abuse this, you can disable this functionality in configuration like this:

```
	'allowSkipping' => false,
```

### How to clear the cache?

[](#how-to-clear-the-cache)

If you want to clear the cached page that you are seeing, specify a true `clearcache` in the HTTP request:

```
http://mypage.com/contacts?clearcache=1

```

The cache for page that you are seeing will be erased. However, if you are using user-specific caching, other users caches will not be reset. If you don't want this to be possible, you can disable it in the config:

```
	'allowClearing' => false,
```

If you update something like main menu or make changes to a page that you want all users to see, you can clear all of the cache using `flushcache` in the url.

```
http://mypage.com/contacts?flushcache=1

```

This functionality is dangerous as someone can easily clear your cache all the time therefore it is disabled by default. If you decide to use it, you have to enable it in the configuration like this:

```
	'allowFlushing' => true,
```

Beware! If possible, we use tags for caching. However, if you are using caching driver that does not support tagging, this flushing might clear all of your applications cache.

### When should I use it?

[](#when-should-i-use-it)

First of all, decide the maximum allowable caching time for a page. How often does the page change? How soon do you want the changes to be visible? Is it ok that a page will refresh once every minute? Once every 10 minutes? Once a week?

When you know the time, try to guess how many users will use a single cache. For example, if you cache a page for 2 minutes, how many users will view it during the time? If the page will receive 100 hits during the 2 minutes, sure it's worth caching. However some old article or a privacy policy page might be viewed less than once every 2 minutes, so no point caching those for 2 minutes as no users would use the cached version.

If you are using user-specific caching, take into account that as well. If each of your logged-in users see a different page, will they actually do enough hits to make the caching worth it?

Changelog
---------

[](#changelog)

It's [here](CHANGELOG.md).

License
-------

[](#license)

This package is licensed under the [MIT license](LICENSE.md).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 88.5% 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 ~215 days

Recently: every ~240 days

Total

9

Last Release

1782d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6674d01479885d0c1929e0529fd4aa68aaf2ca8e4816c774b55ea584de900135?d=identicon)[tontonsb](/maintainers/tontonsb)

---

Top Contributors

[![tontonsb](https://avatars.githubusercontent.com/u/16481303?v=4)](https://github.com/tontonsb "tontonsb (23 commits)")[![matiullah31](https://avatars.githubusercontent.com/u/9604691?v=4)](https://github.com/matiullah31 "matiullah31 (3 commits)")

---

Tags

cachinghacktoberfestlaravellaravel-5-packagemiddlewarelaravelcaching

### Embed Badge

![Health badge](/badges/glaivepro-cachepage/health.svg)

```
[![Health](https://phpackages.com/badges/glaivepro-cachepage/health.svg)](https://phpackages.com/packages/glaivepro-cachepage)
```

###  Alternatives

[maartenstaa/laravel-41-route-caching

This package allows you to cache your routes definitions, thereby speeding up each request.

25371.9k](/packages/maartenstaa-laravel-41-route-caching)[javidalpe/laravel-idempotency

Laravel Idempotency Middleware

2565.9k](/packages/javidalpe-laravel-idempotency)[swiggles/memcache

Memcache driver for Laravel 5

1449.9k1](/packages/swiggles-memcache)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)[matthewbdaly/laravel-repositories

A base repository class and interface, together with a caching decorator. Extend them for use in your own projects.

121.2k2](/packages/matthewbdaly-laravel-repositories)

PHPackages © 2026

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