docs(articles): Magento and Symfony examples side by side, request lifecycle as a Mermaid diagram
en/articles/magento-to-symfony/infrastructure/cache.md
+6
−1
Cache
Magento · CacheInterface
$data = $this->cache->load('faq_popular');
if ($data === false) {
$data = $this->serializer->serialize(
$this->repository->getPopular(5)
);
$this->cache->save($data, 'faq_popular', ['faq'], 3600);
}
$this->cache->clean(['faq']);
Symfony · Cache Contracts
public function __construct(
private TagAwareCacheInterface $cache,
) {}
$popular = $this->cache->get('faq_popular', function (ItemInterface $item) {
$item->expiresAfter(3600);
$item->tag(['faq']);
return $this->questions->findPopularIds(5);
});
$this->cache->invalidateTags(['faq']);
Magento · CacheInterface
$data = $this->cache->load('faq_popular');
if ($data === false) {
$data = $this->serializer->serialize(
$this->repository->getPopular(5)
);
$this->cache->save($data, 'faq_popular', ['faq'], 3600);
}
$this->cache->clean(['faq']);
Symfony · Cache Contracts
public function __construct(
private TagAwareCacheInterface $cache,
) {}
$popular = $this->cache->get('faq_popular', function (ItemInterface $item) {
$item->expiresAfter(3600);
$item->tag(['faq']);
return $this->questions->findPopularIds(5);
});
$this->cache->invalidateTags(['faq']);
get()with a callback protects against stampede: only one process runs the computation.- Pools are defined in
framework.cache.pools: a separate Redis for sessions, a separate one for data. cache:clearclears only the system cache (container, routes, metadata). Data in pools is cleared withcache:pool:clear cache.app.- There is no full page cache system. There is HTTP cache:
#[Cache(public: true, maxage: 600)]on an action,HttpCacheas a PHP reverse proxy, ESI for fragments. Tag-based invalidation in Varnish, likeX-Magento-Tags, is done via FOSHttpCacheBundle.