Giter VIP home page Giter VIP logo

laravel-4-route-cache's Introduction

This is a Laravel 4 package that provides caching for the response of the application.

Installation

Begin by installing this package through Composer. Edit your project's composer.json file to require titzu/cache.

"require": {
        "laravel/framework": "4.0.*",
        "titzu/cache": "dev-master"
},
"require-dev": {
        "phpunit/phpunit": "3.7.*",
        "mockery/mockery": "dev-master@dev"
},
"minimum-stability" : "dev"

Next, update Composer from the Terminal:

composer update

Once this operation completes, the final step is to add the service provider. Open app/config/app.php, and add a new item to the providers array.

'Titzu\RouterCache\RouterCacheServiceProvider'

That's all!

Usage

Register route for caching

You must register the filter with the route

Route::get('/', array('before' => 'cache_get', 'after' => 'cache_set', 'uses' => 'HomeController@show'));

Of course you can also register a group of routes

Route::group(array('before' => 'cache_get', 'after' => 'cache_set'), function()
{
    Route::get('/', 'HomeController@show');
    Route::get('another', 'AnotherController@show');
});

Clear Routes Cache

php artisan router:clear

By default Laravel uses file cache driver for cache storage. Because cache sections are not supported when using the file or database cache drivers and in order not to flush all cache when we need to refresh just the routes cache I keep cached routes in a separate cache entry 'cached_routes'. The router:clear command will then only operate on the keys registered in cached_routes array.

Note

In order to verify that the request is served from the cache or on the fly, I added a new header entry

$response->header('Served-From', 'cache');

and

$response->header('Served-From', 'laravel');

You can then find this using entry developer tools ( firebug for example ).

Contact

Feel free to use, fork, whatever :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.