Open ghost opened 8 years ago
It is mem cache = no? Stack Overflow The HttpRuntime.Cache is available to all "users" (IP's, IIS Session, etc.) on the 'net but HttpContext is only available to the current IIS session? See: Peter Johnson's page. Need it under the correct namespace in VS 2015 hover over HttpContext.Cache in Modules\Orchard.OutputCache\Services\CacheService.cs and see what message it gives ya. using System.Web.Caching; MSDN System.Web.Caching Namespace
To answer the original question, we don't use MemoryCache
as we want a store that can be cleared when the system requests memory. This is the case with HttpContext.Cache
, not with MemoryCache
.
There is a way to tag the cache entries though, that you could use to define custom invalidation. If it lack more extensibility feel free to raise the concern. Also, cache entries are automatically removed when a content item they rendered has been changed.
So my concern is that I want to keep the Cache in memory but I want to invalidate it when an item is changed in distributed environment. So I created a decorator of TagCache
class that hooks on RemoveByTag
and sends message though message bus to all subscribers that will have to invalidate their in memory cache but the _workContext.HttpContext object is disposed when some of the subscribed machines try to invalidate the cache entries for this tagged item.
I created an implementation of the storage provider with the memory cache instead of HttContext.Cache
and it worked as intended.
As far as I know when you add a cache entry into the MemryCache
you can specify the CacheItemPolicy.Priority
to Default and by doing this you will have again a cache that can be cleared when the system requests memory.
@donaldboulton here is something for you to read my friend https://msdn.microsoft.com/en-us/library/dd997357.aspx
Also Microsoft recomeds using of System.Runtime.Caching instead of System.Web.Caching for applications build over .NET Framework 4.0 and above. That is why I wonder why did you decide to use the "old" way of implementation.
Hey I was exploring the code of
DefaultCacheStorageProvider
class because I wanted to invalidate it for different instances with a message bus. But I found that is usesHttpContext.Cache
instead ofMemoryCache
that was causing exception since we don't haveHttpRequest
that will init theHttpContext
. So my question is what is the reason to useHttpContext.Cache
instead ofMemoryCache
?