PHPackages                             anahkiasen/flatten - 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. anahkiasen/flatten

ActiveLibrary[Caching](/categories/caching)

anahkiasen/flatten
==================

A package for the Illuminate framework that flattens pages to plain HTML

1.1.1(10y ago)33113.0k41[5 issues](https://github.com/Anahkiasen/flatten/issues)[2 PRs](https://github.com/Anahkiasen/flatten/pulls)MITPHP

Since Jan 13Pushed 9y ago12 watchersCompare

[ Source](https://github.com/Anahkiasen/flatten)[ Packagist](https://packagist.org/packages/anahkiasen/flatten)[ RSS](/packages/anahkiasen-flatten/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (12)Versions (18)Used By (0)

Flatten
=======

[](#flatten)

[![Build Status](https://camo.githubusercontent.com/216834ef92f8474d0c227db9066ee5af5708c31b5bcc793262f5850b800be066/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f416e61686b696173656e2f666c617474656e2e7376673f7374796c653d666c6174)](https://travis-ci.org/Anahkiasen/flatten)[![Latest Stable Version](https://camo.githubusercontent.com/dbf408ca9c13c703324d7a5a82c8af33137b214812f87214c1d394a6c138dc8d/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e61686b696173656e2f666c617474656e2e7376673f7374796c653d666c6174)](https://packagist.org/packages/anahkiasen/flatten)[![Total Downloads](https://camo.githubusercontent.com/e691384197136bd5d98c5cae1d42243ffe4d513c4bbe7eb8d0253ea3c6624789/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e61686b696173656e2f666c617474656e2e7376673f7374796c653d666c6174)](https://packagist.org/packages/anahkiasen/flatten)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/38d86cc2fd122a825faaaabb7b8e63b96981853607cc19cf26a8a870283d661f/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616e61686b696173656e2f666c617474656e2e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/anahkiasen/flatten/)[![Code Coverage](https://camo.githubusercontent.com/544bc45b2732406a0907a3dfed903651ec6baabcaa3186b7d05246a0f1c14d4d/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616e61686b696173656e2f666c617474656e2e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/anahkiasen/flatten/)[![Dependency Status](https://camo.githubusercontent.com/2a9e64b0483ca9bba28b0b686324e1a9e2d8d31796e696f6addbb77b4bc4e220/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3534346434363738396663346435353566663030303037312f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/544d46789fc4d555ff000071)[![Support via Gittip](https://camo.githubusercontent.com/2700a79f496bdf434db90ac70e5e44e4b01905a98d59b74c66e7d24fcdb2e7c4/687474703a2f2f696d672e736869656c64732e696f2f6769747469702f416e61686b696173656e2e7376673f7374796c653d666c6174)](https://www.gittip.com/Anahkiasen/)

Flatten is a powerful cache system for caching pages at runtime. What it does is quite simple : you tell him which page are to be cached, when the cache is to be flushed, and from there Flatten handles it all. It will quietly flatten your pages to plain HTML and store them. That whay if an user visit a page that has already been flattened, all the PHP is highjacked to instead display a simple HTML page. This will provide an essential boost to your application's speed, as your page's cache only gets refreshed when a change is made to the data it displays.

Setup
-----

[](#setup)

### Installation

[](#installation)

Flatten installs just like any other package, via Composer : `composer require anahkiasen/flatten`.

Then if you're using Laravel, add Flatten's Service Provider to you `config/app.php` file :

```
Flatten\FlattenServiceProvider::class,
```

And its facade :

```
'Flatten' => Flatten\Facades\Flatten::class,
```

### Configuration

[](#configuration)

All the options are explained in the **config.php** configuration file. You can publish it via `artisan vendor:publish`.

Usage
-----

[](#usage)

The pages are cached according to two parameters : their path and their method. Only GET requests get cached as all the other methods are dynamic by nature. All of the calls you'll make, will be to the `Flatten\Facades\Flatten` facade. Query strings are taken into account in the cache and pages will different query strings will have different caches.

### Building

[](#building)

Flatten can cache all authorized pages in your application via the `artisan flatten:build` command. It will crawl your application and go from page to page, caching all the pages you allowed him to.

### Flushing

[](#flushing)

Sometimes you may want to flush a specific page or pattern. If per example you cache your users's profiles, you may want to flush those when the user edit its informations. You can do so via the following methods :

```
// Manual flushing
Flatten::flushAll();
Flatten::flushPattern('users/.+');
Flatten::flushUrl('http://localhost/users/taylorotwell');

// Flushing via an UrlGenerator
Flatten::flushRoute('user', 'taylorotwell');
Flatten::flushAction('UsersController@user', 'taylorotwell');

// Flushing template sections (see below)
Flatten::flushSection('articles');
```

You can also directly inject the responsible class, in a model observer class per example:

```
use Flatten\CacheHandler;

class UserObserver
{
    protected $cache;

    public function __construct(CacheHandler $cache)
    {
        $this->cache = $cache;
    }

    public function saved(User $user)
    {
        $this->cache->flushRoute('users.show', $user->id);
    }
}
```

### Runtime caching

[](#runtime-caching)

You don't have to cache all of a page, you can fine-tune your cache in smaller cached sections.

In PHP you'd do it like this :

```
This will always be dynamic

This will not

```

You can also specify for how long you want that section to be cached by adding an argument to `section` :

```

```

Flatten also hooks into the Blade templating engine for a leaner syntax. Let's rewrite our above example :

```
This will always be dynamic
@foreach($articles as $articles)
	{{ $article->name }}
@endforeach

This will not
@cache('articles', 10)
	@foreach($articles as $article)
		{{ $article->name }}
	@endforeach
@endcache
```

### Kickstarting

[](#kickstarting)

You can speed up Flatten even more by using the `Flatten::kickstart` method. It requires a little more boilerplate code but can enhance performances dramatically. Basically you want to call that before *everything else* (ie. before even loading Composer). On Laravel you'd put that code at the top of `bootstrap/autoload.php`.

You use it like that :

```
require __DIR__.'/../vendor/anahkiasen/flatten/src/Flatten/Flatten.php';

Flatten\Flatten::kickstart();
```

If you have things in your saltshaker, you'll need to find faster raw methods to get these and pass the salts as arguments :

```
require __DIR__.'/../vendor/anahkiasen/flatten/src/Flatten/Flatten.php';

$salt = mysql_query('SOMETHING');
Flatten\Flatten::kickstart($salt);
```

Using outside of Laravel
------------------------

[](#using-outside-of-laravel)

Flatten can easily be used outside of Laravel, for this you'll basically only ever use two methods. What you basically want to do is call `Flatten::start` at the top of the page, and `Flatten::end` at the bottom.

```

```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 97% 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 ~56 days

Recently: every ~10 days

Total

15

Last Release

3862d ago

Major Versions

0.5.1 → 1.0.02015-09-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa3be3e9e416053f11f2296a5fb36f24e45bc70fa293b309d54c2829ded5f373?d=identicon)[Anahkiasen](/maintainers/Anahkiasen)

---

Top Contributors

[![Anahkiasen](https://avatars.githubusercontent.com/u/1321596?v=4)](https://github.com/Anahkiasen "Anahkiasen (191 commits)")[![robbanl](https://avatars.githubusercontent.com/u/922250?v=4)](https://github.com/robbanl "robbanl (4 commits)")[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (2 commits)")

---

Tags

laravelperformancecache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/anahkiasen-flatten/health.svg)

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

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[genealabs/laravel-model-caching

Automatic caching for Eloquent models.

2.4k4.8M26](/packages/genealabs-laravel-model-caching)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[mikebronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k127.1k1](/packages/mikebronner-laravel-model-caching)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)

PHPackages © 2026

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