quinninteractive/silverstripe-clearkey

Silverstripe module to manage partial-cache invalidation

Installs: 672

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

1.0.0 2022-12-20 00:46 UTC

This package is auto-updated.

Last update: 2024-04-14 23:34:53 UTC


README

When using Silverstripe’s partial caching, the keys you use can usually be grouped into two types.

  1. Cache identifier keys, which help tell one cache block from another
  2. Cache clearing keys, which tell us when a block is stale

Take this partial-cache block as an example:

<% cached 'Promo', $ID, $Link, $Promo.LastEdited, $List('SiteTree').max('LastEdited'), $List('SiteTree').count() %>
...
<% end_cached %>

These identifier keys help tell one promo from another:

  • 'Promo'
  • $ID
  • $Link

These clearing keys help tell us when the content is stale:

  • Promo.LastEdited
  • $List('SiteTree').max('LastEdited')
  • $List('SiteTree').count()

Partial caches do a great job with identifier keys, but have to hit the database at every page load to calculate some of the clearing keys, especially the aggregation ones.

ClearKey solves this by letting you manage the calculating of clearing of stale data whenever a relevant data object is saved, instead of on every page load. With ClearKey, the example cache block might look like this:

<% cached $ClearKey('Promo'), $ID, $Link %>
...
<% end_cached %>

You define the clear keys with a corresponding config to describe which classes being updated should invalidate each key. In the example below, the Promo key is invaldated whenever a Promo or SiteTree is saved.

---
Name: clearkey-config
After:
  - '#corecache'
---
QuinnInteractive\ClearKey\Extensions\ClearKeyExtension:
  invalidators:
    Promo:
      - SilverStripe\App\Model\Promo
      - SilverStripe\CMS\Model\SiteTree
    AnotherKey:
      - SilverStripe\App\Model\Something
      - SilverStripe\CMS\Model\Etc

Current version: 1.0.0