Download the PHP package anahkiasen/flatten without Composer
On this page you can find all versions of the php package anahkiasen/flatten. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download anahkiasen/flatten
More information about anahkiasen/flatten
Files in anahkiasen/flatten
Package flatten
Short Description A package for the Illuminate framework that flattens pages to plain HTML
License MIT
Informations about the package flatten
Flatten
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
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 :
And its facade :
Configuration
All the options are explained in the config.php configuration file. You can publish it via artisan vendor:publish
.
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
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
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 :
You can also directly inject the responsible class, in a model observer class per example:
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 :
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 :
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 :
If you have things in your saltshaker, you'll need to find faster raw methods to get these and pass the salts as arguments :
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.
All versions of flatten with dependencies
illuminate/support Version 5.0.*|5.1.*
illuminate/cache Version 5.0.*|5.1.*
illuminate/config Version 5.0.*|5.1.*
illuminate/http Version 5.0.*|5.1.*
illuminate/contracts Version 5.0.*|5.1.*
mrclay/minify Version ^2.2