ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.87k stars 96 forks source link

[QUESTION] Is it possible to have distinct objects for L1 and L2? #321

Open mejas opened 4 weeks ago

mejas commented 4 weeks ago

Hi, right now I am considering using FusionCache as an integration for an existing project, but have a bit of a challenge since it seems that the L1 and L2 caches have to be exactly the same.

A quick overview:

  1. I am currently using IMemoryCache to store compiled Roslyn objects from a string
  2. I would like to add FusionCache, but would like to do the following:
    1. L1 - store the compilation results (delegates) for execution by callers
    2. L2 - store the string data since serializing the delegates is not a guaranteed process

It looks like FusionCache only serializes what it has in L1 for L2 and no way to provide a distinction. Implementing my own IFusionCacheSerializer might work, but if I return the delegate only for L1, the serializer has no access to the string. I could try storing the string as a pair then see it in L2, but now I have a string and wasted memory since its only needed for the serializer.

Why do this?

  1. The compilation process is a bit painful so I would like the results stored in-memory
  2. FusionCache provides a nice backplane integration that I would like to utilize as well (for scaling-up... or having another service signal a change in data)
  3. I would prefer to not roll my own especially with a battle-tested library available

Your thoughts would be greatly appreciated!

jodydonetti commented 4 weeks ago

Uuh, this is an interesting challenge! You made the scenario quite clear, so let me think about it, will let you know.