-
Notifications
You must be signed in to change notification settings - Fork 2.1k
CacheTagHelper should not depend on IMemoryCache #3867
Comments
I agree with the thought in general, but I wonder if this is a case for maybe having different tag helpers? It could be argued that this tag helper is more of a @DamianEdwards any further thoughts? Parking in the Backlog for now. |
I think the cache tag helper should have an attribute to let you select between im-memory and distributed cache. |
Unfortunately that breaks DI 😦 🐼 It would mean you can't take the cache interface in the ctor anymore: https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs#L47 You'd have to reach into the service provider and resolve it. That's the real reason I was suggesting multiple middlesware. |
You can take a dependency on both. |
But it doesn't actually require both, so that's a bit dirty. |
If Damian's advice is to have an attribute to target which storage for each tag (which is what I understood), then it actually requires both services. You can make them lazy if you want, still, not a broken design IMO. |
Supporting |
The case is every time I show it to people, they ask for it. StackOverflow is well known for caching rendered HTML in Redis. He user scenario is sound. Don't really care how you implement it, as long as it's in the one helper. |
Moving out of backlog. @sebastienros please post a proposal to discuss. |
I don't think it's necessary for RTM. We're really beyond the time to be making changes like this. |
If @sebastienros can round something up would you want to take it? |
Are you telling me that it's in effect, free? 😄 |
Someone has to approve the design and then it needs a code review. Nothing's free 😄 |
Yeah, we have to stop some time mate. Good one for 1.1 👍 |
ProposalKeep the current default behavior and store everything using the Add an optional Example:
If the application runs on a single instance the use of Caveats
|
In the distributed cache scenario you'd need to also require the user to provide some sort of cache key so it's the same across nodes. @sebastienros wasnt your concern with this issue initially finding a way to separate types of caches used? Aka, the cache |
The key is already created and unique as part as the current implementation. |
Actually you are right, we need a custom user key, I will look into the current implementation. |
Currently it's using the |
Related annoucements: |
IMemoryCache
is a perfect match for single node scenarios in CacheTagHelper but it breaks if the website runs on more nodes, as each node would return different contents. The issue here is that there is no way to change it.I think it would be better to either:
IDitributedCache
as the default implementation usesIMemoryCache
which means it would work the same as today on a single instance, and not be broken on multiple instances.IMemoryCache
,IDistributedCache
or another implementation. Each site is different, and locking down the cache tag storage might be an issue. And having the to share the same implementation for controllers and tags might not make sense either.A different approach would be to use a message bus implementation to invalidate
IMemoryCache
entries across nodes, but I don't think it's been planned either./cc @NTaylorMullen
The text was updated successfully, but these errors were encountered: