cofoundry icon indicating copy to clipboard operation
cofoundry copied to clipboard

Custom entity caching

Open dumboster opened this issue 6 years ago • 4 comments

Hello,

In order to save configuration, I'm using custom entities. So Administrators can change this values via the back-office. Unfortunately the custom entities are not saved in cache. I found ICustomEntityCache implementation but it caches only CustomEntityRoute which cannot contain Model data.

Is it possible to add a method on this interface in order to cache object with Model data (for example CustomEntityRenderSummary objects) ? It could be loaded by customEntityTypeCode, like the existing ICustomEntityCache.GetOrAddAsync method.

FYI, I currently use the method ICustomEntityService.GetCustomEntityRenderSummariesByDefinitionCodeAsync(...) in my code (seen in Cofoundry.Samples.Menus project).

Thanks !

dumboster avatar Oct 02 '18 16:10 dumboster

At the moment (as you point out) we only cache the routing information, which ensures the route checking is fast, but the cache size is small. Custom entities can be used in any number of ways and the caching strategy could change depending on the type, so this isn't as straight-forward as adding everything to the cache.

I think there's a bigger job here to look at caching in general and how we can optionally provide layered caching in for certain entities.

For now I there's two options for you:

  1. Use MVC output caching at the view level, the draw-back being that you won't be able to control the cache invalidation and so will have to keep it on a short timer
  2. In code you can use the Cofoundry cache factory to build your own cache, and combine it with the message aggregator to break the cache when your custom entity has been updated. The list of subscribable messages (events) are listed in the docs here - ICustomEntityContentUpdatedMessage is probably the one you're after.

HeyJoel avatar Oct 02 '18 16:10 HeyJoel

Thanks a lot for your response ! I'll try to use ICustomEntityContentUpdatedMessage which seems to be the right thing to do in my case.

dumboster avatar Oct 03 '18 06:10 dumboster

It works with message aggregator and cache factory, with few modifications of my code. Thanx :)

dumboster avatar Oct 03 '18 09:10 dumboster

Sweet! I'm going to keep this open as I think there's some work items to come out of this:

  • Documentation improvements or examples of creating custom caching using the cache factory and message aggregator.
  • Exploration of optional/layered caching techniques to automate some of this based on config.

I'll probably split these out into separate issues a bit further down the line.

HeyJoel avatar Oct 03 '18 10:10 HeyJoel