There is no license information available for the latest version (1.0.0) of this package.

Simplify partial caching queries for folders of DataObjects associated with Images by cache busting these DataObjects when the associated image is edited

1.0.0 2016-01-18 16:35 UTC

This package is auto-updated.

Last update: 2024-05-27 07:00:19 UTC


##Partial Cache Busting After Image Editing Build Status Scrutinizer Code Quality Code Coverage Build Status codecov.io

Latest Stable Version Latest Unstable Version Total Downloads License Monthly Downloads Daily Downloads

Dependency Status Reference Status


This module enables the updating of the LastEdited value of DataObjects associated with Images being edited. This simplifies partial caching of for example the rendering of a folder of pages which are each represented by an image. If the cache key is based on the LastEdited value of the DataObjects in the folder, then when an image is edited (e.g. refocused with the FocusPoint module) the change will not show, as the cache key knows nothing about the LastEdited field of the images of child pages.

The options to ensure image updates show in the above scenario when using partial caching are these:

  • Use max(LastEdited) of all images - inefficient
  • Have a parital cache query around each child page checking for the LastEdited field of the page's image. This is also inefficient as one database query is made per child page rendered.
  • Add a method in the folder object to calculate the cache key based on a database join query.

At the expense of a slightly more expensive write, we can use the LastEdited date of the child pages as a cache key that will also take into account image edits.

##Configuration The classes to check for image IDs are configured as follows, in an arbitrarily named .yml file under any module's _config directory, e.g. imageeditpartialcachebust.yml. There are three keys under 'ImageEditCacheBust'

  • Stages: the stages configured in your default configuration, the default being Stage and Live
  • SiteTree: a nested array of ClassName mapped to the field containing the image ID.
  • DataObject: a nested array of ClassName mapped to the field containing the image ID.

In the example below every time an image is refocussed every PageWithImage data object will have it's LastEdited field updated to now (thus busting fragment caches) if the value of MainImageID matches the ID of the image being edited. Similarly with both SlidePage and Staff, except this time checking the PhotoID field.

Name: imageeditpartialcachebuster
After: framework/routes#coreroutes

  Stages: ['Stage','Live']
    PageWithImage : 'MainImageID'
    Product : 'ImageID'
    SlidePage : 'PhotoID'
    Staff : 'PhotoID'
    GalleryImage : 'ImageID'

##Template Example Using the module mentioned in the related modules section below, an example template for a folder containing several PageWithImage pages rendering their images looks like this:

<div class="row">
<div class="small-12 columns">
<% cached ID, LastEdited,Locale,$CacheKey('folderofpagewithimages','ChildPage') %>
<ul class="small-block-grid-2 medium-block-grid-3">
<% loop AllChildren %>
<li><div class="captionedImage">
<a href="$Link"><img class="shadowbox sliderImage" data-interchange="[$PortletImage.CroppedFocusedImage(390,260).URL, (default)],[$PortletImage.CroppedFocusedImage(236,157).URL, (small)],[$PortletImage.CroppedFocusedImage(236,157).URL, (medium)],[$PortletImage.CroppedFocusedImage(390,260).URL, (large)]"/>
<noscript><img src="$PortletImage.SetWidth(640).URL"></noscript></a>
<% end_loop %>
<% end_cached %>
<% include TopAndLike %>

#Related Modules The cachkey helper module, https://github.com/gordonbanderson/weboftalent-cachekey-helper, enables all partial cache key values to be accessed in a single database query, vastly reducing the number of queries performed when checking for partial cache validity.