This document discusses developing cacheable backend applications. It covers topics like identifying slow parts of an application to optimize, using caching to improve performance once optimization limits are reached, different HTTP caching mechanisms, conditional requests to only fetch changed data, edge caching with reverse proxies, content composition with placeholders, cache variations based on request headers, purging cached content, and strategies when caching HTTP responses is not possible. The target is to design software with caching in mind from the start for improved control and consistent caching behavior.
31. ✓STATELESS
✓WELL-DEFINED TTL
✓CACHE / NO-CACHE PER RESOURCE
✓CACHE VARIATIONS
✓CONDITIONAL REQUESTS
✓PLACEHOLDERS FOR NON-CACHEABLE CONTENT
IN AN IDEAL WORLD
58. <?php
namespace AppEventListener;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpKernelEventGetResponseEvent;
use SymfonyComponentHttpKernelEventFilterResponseEvent;
use SymfonyBundlesRedisBundleRedisClient as RedisClient;
class ConditionalRequestListener
{
protected $redis;
public function __construct(RedisClient $redis)
{
$this->redis = $redis;
}
protected function isModified(Request $request, $etag)
{
if ($etags = $request->getETags()) {
return in_array($etag, $etags) || in_array('*', $etags);
}
return true;
}
...
src/EventListener/ConditionalRequestListener.php
70. EDGE SIDE INCLUDES
✓ PLACEHOLDER
✓ W3C STANDARD
✓ PROCESSED "ON THE EDGE" (E.G. VARNISH)
✓ OUTPUT IS A COMPOSITION OF BLOCKS
✓ STATE PER BLOCK
✓ TTL PER BLOCK
<esi:include src="/header" />
74. EDGE SIDE INCLUDES
✓ SERVER-SIDE
✓ STANDARDIZED
✓ PROCESSED ON THE
“EDGE”, NOT IN THE
BROWSER
✓ GENERALLY FASTER
- SEQUENTIAL
(ONLY PARALLEL IN ENTERPRISE VERSION)
- ONE FAILS, ALL FAIL
- LIMITED IMPLEMENTATION
IN VARNISH
75. AJAX
✓ CLIENT-SIDE
✓ COMMON KNOWLEDGE
✓ PARALLEL PROCESSING
✓ GRACEFUL DEGRADATION
- PROCESSED BY THE
BROWSER
- EXTRA ROUNDTRIPS
- SOMEWHAT SLOWER
83. WHAT IF THE CONTENT
OF A URL VARIES
BASED ON THE VALUE
OF A REQUEST
HEADER?
84. CACHE VARIATIONS
HTTP/1.1 200 OK
Host: localhost
Content-Language: en
Content-type: text/html; charset=UTF-8
Hello world output
GET / HTTP/1.1
Host: localhost
Accept-Language: en, nl, de