1

I wanted to know if the web.config caching section is the same cache used by the MVC HttpRuntime.Cache.

If they are, is there any way to use them separately ? I want to have a 10 minutes cache for my pages ( routes ) and a 1 hour cache for my static content: html, css, js, etc.

This is my .NET cache:

HttpRuntime.Cache.Insert(
    key               : cacheKey,
    value             : clone,
    dependencies      : null,
    absoluteExpiration: DateTime.UtcNow.AddMinutes( 10 ),
    slidingExpiration : Cache.NoSlidingExpiration,
    priority          : CacheItemPriority.NotRemovable,
    onRemoveCallback  : null
);

This is how i use the web.config cache:

[OutputCache( CacheProfile = "Cache1H" )]

This is my web.config cache:

<system.web>
    <caching>
        <outputCacheSettings>
            <outputCacheProfiles>
                <add name="Cache1H" duration="3600" varyByParam="none" noStore="true" location="Client" />
            </outputCacheProfiles>
        </outputCacheSettings>
    </caching>
</system.web>

EDIT

How could i reset or expire the HttpRuntime cache from another application ? Let's say i have a website and i want do reset it at my admin so the website would update the cache and get the new information.

Ariel
  • 911
  • 1
  • 15
  • 40

1 Answers1

2

Both are different caching types which can be used in MVC.

Output caching can be use to cache the complete page including data either on client or server side. Checkout http://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/improving-performance-with-output-caching-cs for more details

The other type caching is Memory caching HttpRuntime.Cache.Insert where you can cache the data using key and value pairs for certain period of time.Checkout memory caching details at https://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache(v=vs.110).aspx

Srinivas Ramakrishna
  • 1,294
  • 13
  • 21
  • But one won't interfere with the other right ? They are different caches ? – Ariel Dec 01 '15 at 13:30
  • Both are different cache. It depends on how exactly you are using both the cache. If you just want to cache the data you can use Memory caching and if you want to cache the entire page on client side or server side then use output caching. – Srinivas Ramakrishna Dec 01 '15 at 13:55
  • I'm using them as i explained in my question, would i be able to reset the HttpRuntime cache from another application ? – Ariel Dec 01 '15 at 13:57
  • Yes you would be able to reset the HttpRuntime cache from another application. There are various ways to clear cache refer http://stackoverflow.com/questions/2452722/clear-asp-net-cache-from-outside-of-application-not-using-source-code – Srinivas Ramakrishna Dec 01 '15 at 14:01
  • That didn't really work, i tried to remove the cache created at my site that runs on MVC from my admin area that is using .NET and cache wasn't removed. I used HttpRuntime.Cache.Remove( cacheKey ); – Ariel Dec 01 '15 at 15:57