HttpCacheBundle¶
The SuluHttpCache bundle provides integration between Sulu and HTTP caching proxies using the FOSHttpCacheBundle.
CacheManager¶
The CacheManager can be used to invalidate the cache.
For example:
...
$cacheManager = $this->get('sulu_http_cache.cache_manager');
$cacheManager->invalidatePath($path, $headers);
...
CacheLifetime¶
CacheLifetimeEnhancer¶
Use this service to set the cache lifetime from a Sulu structure to the response. The structure needs to be an instance of PageInterface.
Note: This service is only available when a proxy client is correctly configured.
For example:
...
if ($this->has('sulu_http_cache.cache_lifetime.enhancer')) {
$cacheLifetimeEnhancer = $this->get('sulu_http_cache.cache_lifetime.enhancer');
$cacheLifetimeEnhancer->enhance($response, $structure);
}
...
CacheLifetimeResolver¶
The cache lifetime resolver resolves the given cache lifetime metadata based on the type and returns an absolute cache lifetime in seconds.
Configuration¶
The debug feature simply adds debug information to your response:
For example:
X-Cache: HIT/MISS
Enable this feature via configuration:
sulu_http_cache:
debug:
enabled: true
Proxy Clients¶
At the moment Sulu works with following proxy clients:
Symfony Http Cache¶
The Symfony HTTP cache is the default caching client for Sulu. It is integrated directly into Sulu.
It works by “wrapping” the kernel. This is done by the kernel itself, but in the front controller
at public/index.php
the cache kernel has to be used:
// ...
if ('dev' !== $_SERVER['APP_ENV'] && SuluKernel::CONTEXT_WEBSITE === $suluContext) {
$kernel = $kernel->getHttpCache();
}
It will need to be disabled (i.e. the lines need to be removed) when using varnish.
Varnish¶
The varnish proxy client is provided by the FOSHttpCache component.
See Caching with Varnish for more information about setting up varnish.
Default configuration¶
# Default configuration for extension with alias: "sulu_http_cache"
sulu_http_cache:
tags:
enabled: false
cache:
max_age: 240
shared_max_age: 240
proxy_client:
symfony:
enabled: false
# Addresses of the hosts Symfony is running on. May be hostname or ip, and with :port if not the default port 80.
servers:
# Prototype
name: ~
# Default host name and optional path for path based invalidation.
base_url: null
varnish:
enabled: false
# Addresses of the hosts Varnish is running on. May be hostname or ip, and with :port if not the default port 80.
servers:
# Prototype
name: ~
# Default host name and optional path for path based invalidation.
base_url: null
debug:
# Whether to send a debug header with the response to trigger a caching proxy to send debug information. If not set, defaults to kernel.debug.
enabled: true