How can we know if a page in Drupal 8 has changed?

Submitted by Anonymous (not verified) on Fri, 02/10/2015 - 15:27

<p>This was a question I got from a client. So I set to work on finding a solution to alert the team who needed to know when a page has changed.</p><p><b>TL;DR</b>: <a href="https://www.drupal.org/developing/api/8/cache/tags&quot; target="_blank">CacheTags</a>.</p><!-- more --><p>Drupal has an awesome caching layer. It makes use of cache tags, these tags can be invalidated when something changes. For example if this is a view called “frontpage”, it would output the cache tag &ldquo;view:frontpage&rdquo;. This view lists a bunch of nodes, each with their own cache tag, &ldquo;node:1&rdquo;, &ldquo;node:2&rdquo; etc. When node 2 is edited, it’s cache tag and the frontpage view cache tag would be invalidated.</p><p>Taking this into account if we want to know what pages have changed, we need to know what cache tags the page has, then what cache tags have been invalidated.</p><p>The client already has a crawler to check their sites, this can look at the <code>X-Drupal-Cache-Tags</code> header and capture the cache tags the page has. So all we need now is a way of telling the crawler what cache tags have been invalidated.</p><p>Welcome to the <a href="https://www.drupal.org/project/cachetag_notify&quot; target="_blank">CacheTag Notify</a> module. This has a simple settings page where an endpoint URL can be added. Then every time a cache tag is invalidated it gets POSTed to the endpoint as a JSON string. The crawler will then need to to lookup which pages are using the invalidated cache tags, then it knows which have changed.</p><p>The CacheTag Notify module works by adding <code>CacheTagsInvalidator</code> service. The <code>invalidateTags</code> method is passed an array of invalited tags, this is then POSTed to the endpoint url using Guzzle. Overall a very, very simple, but effective solution.</p>

Add new comment