Giter Club home page Giter Club logo

execution-cache-bundle's Introduction

Installation

This bundle provides a caching mechanism at application level. It's very similar to HTTP caching at reverse-proxy level, but execution cache is done later. This way, the request has already been checked by the security layer but we can running the controller twice if the result should be the same.

The cache storage will provide different result based on Request headers and body. If the exact same request is sent twice and the response is cached, the controller is not run and the response is sent.

Step 1: Install the AdapterBundle

This bundle uses a PSR-6 cache implementation provided by https://github.com/php-cache/adapter-bundle. It can be Memcached, Redis, Filesystem, Void or even your own implementation. The choice is yours!

Please check their docs before installing this bundle.

Step 2: Install the Bundle

Open a command console, go to your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require stadline/execution-cache-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 3: Enable the Bundle

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Stadline\ExecutionCacheBundle\StadlineExecutionCacheBundle(),
        );

        // ...
    }

    // ...
}

Step 4: Add the ExecutionCache annotation

To enable the cache, you must add an annotation on the controller method you want to be cached.

<?php

namespace AcmeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Stadline\ExecutionCacheBundle\Annotation\ExecutionCache;

class BrandController extends Controller
{
    /**
     * @ExecutionCache(lifetime=3600)
     */
    public function indexAction(Request $request)
    {
        // do some heavy stuff
    }
}

You can set a cache TTL if you want, but it's optional.

That's all!

Configuration

You can override the configuration easily

# Default configuration for extension with alias: "stadline_execution_cache"
stadline_execution_cache:
    storage:
        prefix:               exc_
        default_ttl:          300
        pool_adapter:         cache

You can set the key prefix and the default TTL.

The pool_adapter can be any CachePool implementation, check http://www.php-cache.com/en/latest/symfony/adapter-bundle/#configuration

For example, if you defined a provider called my_filesystem you can use cache.provider.my_file_system (or just cache if it's the default provider)

execution-cache-bundle's People

Contributors

alex-pex avatar thomasglachant avatar clementtalleu avatar

Stargazers

Fedy avatar NIco avatar Desjardins Jérôme avatar

Watchers

James Cloos avatar  avatar Jérôme Weber avatar Raphael Bonini avatar Elliott Froigné avatar Manon Hernas avatar NIco avatar Aurélien G avatar Manon Lecomte avatar  avatar  avatar Fabien Ravez avatar Jessy Lenne avatar  avatar

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.