Simplify partial caching queries for folders of DataObjects associated with Images by cache busting these DataObjects when the associated image is edited
##Partial Cache Busting After Image Editing
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:
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.
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'
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 --- ImageEditCacheBust: Stages: ['Stage','Live'] SiteTree: PageWithImage : 'MainImageID' Product : 'ImageID' SlidePage : 'PhotoID' Staff : 'PhotoID' DataObject: GalleryImage : 'ImageID'
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"> $BreadCrumbs <h1>$Title</h1> $Content <% cached ID, LastEdited,Locale,$CacheKey('folderofpagewithimages','ChildPage') %> <ul class="small-block-grid-2 medium-block-grid-3"> <% loop AllChildren %> <li><div class="captionedImage"> <h3>$Title</h3> <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> </div> </li> <% end_loop %> </ul> <% end_cached %> $Form $PageComments </div> <% include TopAndLike %> </div>
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.
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem