|
| 1 | +Installation |
| 2 | +============ |
| 3 | + |
| 4 | +This bundle provides a caching mechanism at application level. It's very similar to HTTP caching at reverse-proxy level, but execution |
| 5 | +cache is done later. This way, the request has already been checked by the security layer but we can running the controller twice if |
| 6 | +the result should be the same. |
| 7 | + |
| 8 | +The cache storage will provide different result based on Request headers and body. If the exact same request is sent twice and the |
| 9 | +response is cached, the controller is not run and the response is sent. |
| 10 | + |
| 11 | +Step 1: Install the AdapterBundle |
| 12 | +--------------------------------- |
| 13 | + |
| 14 | +This bundle uses a PSR-6 cache implementation provided by https://github.com/php-cache/adapter-bundle. It can be Memcached, Redis, |
| 15 | +Filesystem, Void or even your own implementation. The choice is yours! |
| 16 | + |
| 17 | +Please check their docs before installing this bundle. |
| 18 | + |
| 19 | +Step 2: Install the Bundle |
| 20 | +-------------------------- |
| 21 | + |
| 22 | +Open a command console, go to your project directory and execute the |
| 23 | +following command to download the latest stable version of this bundle: |
| 24 | + |
| 25 | +```bash |
| 26 | +$ composer require stadline/execution-cache-bundle |
| 27 | +``` |
| 28 | + |
| 29 | +This command requires you to have Composer installed globally, as explained |
| 30 | +in the [installation chapter](https://getcomposer.org/doc/00-intro.md) |
| 31 | +of the Composer documentation. |
| 32 | + |
| 33 | +Step 3: Enable the Bundle |
| 34 | +------------------------- |
| 35 | + |
| 36 | +Then, enable the bundle by adding the following line in the `app/AppKernel.php` |
| 37 | +file of your project: |
| 38 | + |
| 39 | +```php |
| 40 | +<?php |
| 41 | +// app/AppKernel.php |
| 42 | + |
| 43 | +// ... |
| 44 | +class AppKernel extends Kernel |
| 45 | +{ |
| 46 | + public function registerBundles() |
| 47 | + { |
| 48 | + $bundles = array( |
| 49 | + // ... |
| 50 | + |
| 51 | + new Stadline\ExecutionCacheBundle\StadlineExecutionCacheBundle(), |
| 52 | + ); |
| 53 | + |
| 54 | + // ... |
| 55 | + } |
| 56 | + |
| 57 | + // ... |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +Step 4: Add the ExecutionCache annotation |
| 62 | +----------------------------------------- |
| 63 | + |
| 64 | +To enable the cache, you must add an annotation on the controller method you want to be cached. |
| 65 | + |
| 66 | +```php |
| 67 | +<?php |
| 68 | + |
| 69 | +namespace AcmeBundle\Controller; |
| 70 | + |
| 71 | +use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
| 72 | +use Symfony\Component\HttpFoundation\Request; |
| 73 | +use Stadline\ExecutionCacheBundle\Annotation\ExecutionCache; |
| 74 | + |
| 75 | +class BrandController extends Controller |
| 76 | +{ |
| 77 | + /** |
| 78 | + * @ExecutionCache(lifetime=3600) |
| 79 | + */ |
| 80 | + public function indexAction(Request $request) |
| 81 | + { |
| 82 | + // do some heavy stuff |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +You can set a cache TTL if you want, but it's optional. |
| 88 | + |
| 89 | +_That's all!_ |
| 90 | + |
| 91 | +Configuration |
| 92 | +------------- |
| 93 | + |
| 94 | +You can override the configuration easily |
| 95 | + |
| 96 | +``` |
| 97 | +# Default configuration for extension with alias: "stadline_execution_cache" |
| 98 | +stadline_execution_cache: |
| 99 | + storage: |
| 100 | + prefix: exc_ |
| 101 | + default_ttl: 300 |
| 102 | + pool_adapter: cache |
| 103 | +``` |
| 104 | + |
| 105 | +You can set the key prefix and the default TTL. |
| 106 | + |
| 107 | +The pool_adapter can be any CachePool implementation, check http://www.php-cache.com/en/latest/symfony/adapter-bundle/#configuration |
| 108 | + |
| 109 | +For example, if you defined a provider called ```my_filesystem``` you can use ```cache.provider.my_file_system``` (or just ```cache``` |
| 110 | +if it's the default provider) |
0 commit comments