Heyday/silverstripe-cacheinclude - how to create dynamic cache key based off of object id

I am looking into using heyday/ silverstripe-cacheinclude on a project and there are two items that I am having issues with

  1. I have a output display of blog posts and on that display I put the number of comments. If I include just the BlogPost in my cache config contains - example -

     Blog:
       context: full
       contains:
         - SilverStripe\Blog\Model\BlogPost
       expires: +1 hour
       member: true
    

If a new comment is added to this post the cache won’t update. If I include the comment class in contains like -

    Blog:
      context: full
      contains:
        - SilverStripe\Blog\Model\BlogPost
        - SilverStripe\Comments\Model\Comment
      expires: +1 hour
      member: true

This works but if anyone comments on any post then all blog caches are invalidated. I also have comments on other sections of the site and other dataobjects so it doesn’t make sense that then any time a user comments on some other section of the site the blog cache would then expire since nothing has changed in that group.

Now I do see that this module handles many_many lists and when those are updated in invalidates as expected but I can’t seem to figure out how to limit with related $has_many or $has_one data.

  1. I have a feed on the site that is user specific and is pretty random so sort of the same issue as above. I want to basically cache each card in that feed so queries like comment count, likes etc don’t need to recalculate again until those change. I see that you can create your own key interface. GitHub - heyday/silverstripe-cacheinclude: Fast Caching for SilverStripe Does anyone know how to create the key where it is referencing that specific object though. With default partial caching from silverstripe you could include things like <% cache ‘BlogPost.$ID’… %> With this module the configurations seem to be more broad whereas it seems it was much easier to target specific objects previously.

@obj63mc did you get anywhere with this? I’ve used cacheinclude quite a few times in the past and wondered the same thing but never figured it out myself…

I unfortunately have not found a way to get this working.

I basically implemented old school partial caching for these sorts of objects as the queries I was using (counts) and last edit checks were faster than just querying all the content. Again would still love a better way to cache/invalidate objects in a template but at this time I haven’t found a way to do so.

That’s what I ended up doing too… thanks for replying :slight_smile: If I come up with something I’ll ping you a message on here :+1: