El paquete BlockBundle integra con el SonataCacheBundle para proporcionar varias soluciones de almacenamiento en caché. Dale un vistazo a los adaptadores disponibles en el SonataCacheBundle para ver todas las opciones.
El BlockBundle además proporciona sus propios adaptadores para:
Nota
Es aconsejable almacenar todas las opciones en el bloque documento al utilizar la memoria caché.
La funcionalidad de memorización en caché es opcional y depende del SonataCacheBundle.
La instalación está dividida entre el SonataCacheBundle, el SymfonyCmfBlockBundle y el SonataBlockBundle:
- YAML
# app/config/routing.yml # ... # rutas a los adaptadores de caché SymfonyCmfBlockBundle block_cache: resource: "@SymfonyCmfBlockBundle/Resources/config/routing/cache.xml" prefix: /
- YAML
# app/config/config.yml sonata_block: # ... blocks: symfony_cmf.block.action: # Usa el id del adaptador del servicio cache cache: symfony_cmf.block.cache.js_async
Lo siguiente sucede al dibujar un bloque la memoria caché:
Nota
Los adaptadores de caché adicionales del BlockBundle siempre regresan la caché encontrada, tiene una apariencia similar a la del método has de los adaptadores en el SonataCacheBundle para ver cómo responden ellos.
Si caché está marcado y el adaptador de caché indica que ninguna caché se encontró, el flujo de trabajo procede así:
The block service has the responsibility to generate the cache keys, the method getCacheKeys returns these keys, see Bloque de servicio.
The block services shipped with the BlockBunde use the getCacheKeys method of the Sonata\BlockBundle\Block\BaseBlockService, and return:
Nota
If block settings need to be persisted between requests it is advised to store them in the block document. Alternatively they can be added to the cache keys. However be very cautious because, depending on the adapter, the cache keys can be send to the browser and are not secure.
The extra cache keys array is used to store metadata along the cache element. The metadata can be used to invalidate a set of cache elements.
The contextual cache array hold the object class and id used inside the template. This contextual cache array is then added to the extra cache key.
This feature can be use like this $cacheManager->remove(array('objectId' => 'id')).
Of course not all cache adapters support this feature, varnish and mongodb do.
The BlockBundle also has a cache invalidation listener that calls the flush method of a cache adapter automatically when a cached block document is updated or removed.
The following parameters can be used in the sonata_block_render code in your Twig template when using cache:
{{ sonata_block_render(
{ 'name': 'rssBlock' },
true,
{ 'extra_key': 'my_block' }
) }}
This extends the default EsiCache adapter of the SonataCacheBundle.
# app/config/config.yml
symfony_cmf_block:
# ...
caches:
esi:
token: a unique security key # a random one is generated by default
servers:
- varnishadm -T 127.0.0.1:2000 {{ COMMAND }} "{{ EXPRESSION }}"
This extends the default SsiCache adapter of the SonataCacheBundle.
# app/config/config.yml
symfony_cmf_block:
# ...
caches:
ssi:
token: una clave de seguridad única # de manera predeterminada se genera una aleatoria
Renders the block using javascript, the page is loaded and not waiting for the block to be finished rendering or retrieving data. The block is then asynchronously or synchronously loaded and added to the page.