eglobal / template-cache-bundle
Symfony template caching functionality.
Installs: 3 250
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 3
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=7.1
- doctrine/annotations: ~1.0
- psr/log: ~1.0
- sensio/framework-extra-bundle: ^5.2
- symfony/asset: ^4.0
- symfony/console: ^4.0
- symfony/framework-bundle: ^4.0
- symfony/routing: ^4.0
- symfony/templating: ^4.0
- symfony/translation: ^4.0
- symfony/twig-bundle: ^4.0
Requires (Dev)
This package is not auto-updated.
Last update: 2025-04-25 13:26:25 UTC
README
Installation
Install this bundle using Composer. Add the following to your composer.json:
{ "require": { "eglobal/template-cache-bundle": "~1.0" } }
Register bundle in the app/AppKernel.php:
public function registerBundles() { $bundles = [ // ... new EGlobal\Bundle\TemplateCacheBundle\EGlobalTemplateCacheBundle(), ]; }
Update config:
parameters: locales: - en - es - de # If using Assetic, add the bundle to the config assetic: bundles: - EGlobalTemplateCacheBundle eglobal_template_cache: # Locales to be cached locales: "%locales%" # Cache only exposed routes exposed_routes_only: false # Public directory to store cached templates cache_dir: '%kernel.root_dir%/../web/templates' # Public prefix of cached templates public_prefix: '/templates' # Directories to search cacheable templates in root_dirs: - "@AcmeFooBundle/Controller" - "@AcmeBarBundle/Controller/Cacheable"
Example usage
Mark controller routes as cacheable
<?php namespace Acme\FooBundle\Controller; use EGlobal\Bundle\TemplateCacheBundle\Annotation\CacheableTemplate; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class MyController extends Controller { /** * @Route(methods={"GET"}, path="/my/foo.html", name="my.template.foo", options={"expose"=true}) * @CacheableTemplate("AcmeFooBundle:Template:foo.html.twig") */ public function fooAction() { // Your controller logic } /** * @Route(methods={"GET"}, path="/my/bar.svg", name="my.template.bar", options={"expose"=true}) * @CacheableTemplate("AcmeFooBundle:Template:bar.svg.twig") */ public function barAction() { // Your controller logic } }
Dump templates into cache files
$ php bin/console eglobal:template-cache:dump
Add assets to your template
... <head> <script type="text/javascript" src="{{ asset('bundles/eglobaltemplatecache/js/template-cache.js') }}"></script> {% if not app.debug %} <script type="text/javascript" src="{{ asset(jsTemplateMapFileName(app.request.locale)) }}"></script> {% endif %} </head> ...
Use cacheable template paths in your code
// This will return some path like '/templates/en/f9d15a8be554432de01799a8c51d123f.html' var fooCachedUrl = TemplateCache.get('my.template.foo'); // This will return some path like '/templates/en/f9d15a8be554432de01799a8c51d123f.svg' var barCachedUrl = TemplateCache.get('my.template.bar');