2

I recently made a plugin that tries to keep the existing cache warm. It does this by listening to the elements.onBeforeSaveElement event, grabbing the id of that element and finding all the paths in the craft_templatecaches table then calls them with Guzzle.

The part I'm struggling with is the element id - when the event fires I just get the id of the element that first fired, in most cases the Entry. How do I ensure I get all of the correct cacheIds from the craft_templatecacheelements table? I only have the one element id, is there a way of ensuring I have all of the involved element ids?

I tried getting element ids from craft_relations by sourceId but still don't seem to be able to replicate the same kind of behaviour that the native cache clearing does. When I save an entry I get a bunch of element ids in the DeleteStaleTemplateCaches Task settings but can't find a way to get that same set of ids before the element saves.

I feel like I'm missing something fundamental ...

  • 2
    Wouldn't you just be following similar logic as the DeleteStaleTemplateCachesTask does in getTotalSteps() and runStep()? – Brad Bell Jun 23 '15 at 17:22
  • Clearly I was missing something fundamental. /facepalm – Josh Angell Jun 23 '15 at 18:53
  • lol - be sure and add an official answer when you get it sorted. :) – Brad Bell Jun 23 '15 at 18:54
1

This is not much of an answer but basically Brad was right - I just needed to replicate the logic that the DeleteStaleTemplateCachesTask does in its getTotalSteps() and runStep() methods.

This allows you to work out exactly what caches will be just about to be deleted. I'm not going to post the code here as it is literally a copy/paste from the DeleteStaleTemplateCachesTask.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.