There is a way to update the limit, but I would highly recommend using a different caching system (more on this below).
.NET cache
To learn more about the limitation of .NET caching, read this excellent answer from the Microsoft.NET Team Member .
If you want to see the current limits of .NET Cache, you can try:
var r = new Dictionary<string, string>(); using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache % Machine Memory Limit Used", true)) { pc.InstanceName = "__Total__"; r.Add("Total_MachineMemoryUsed", String.Concat(pc.NextValue().ToString("N1"), "%")); } using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache % Process Memory Limit Used", true)) { pc.InstanceName = "__Total__"; r.Add("Total_ProcessMemoryUsed", String.Concat(pc.NextValue().ToString("N1"), "%")); } using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache API Entries", true)) { pc.InstanceName = "__Total__"; r.Add("Total_Entries", pc.NextValue().ToString("N0")); } using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache API Misses", true)) { pc.InstanceName = "__Total__"; r.Add("Total_Misses", pc.NextValue().ToString("N0")); } using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache API Hit Ratio", true)) { pc.InstanceName = "__Total__"; r.Add("Total_HitRatio", String.Concat(pc.NextValue().ToString("N1"), "%")); } using (var pc = new PerformanceCounter("ASP.NET Applications", "Cache API Trims", true)) { pc.InstanceName = "__Total__"; r.Add("Total_Trims", pc.NextValue().ToString()); }
Memcached
I am currently using Memcached , and if you host your site somewhere, you can use a paid service, for example:
Or, if you use your own server, you can download Couchbase Community Edition and host your own.
Here you will find more questions about using MemCache, for example:
Make room for any cache system
To use a different caching system without changing the code, you can use to create an interface, for example
public interface ICacheService { T Get<T>(string cacheID, Func<T> getItemCallback) where T : class; void Clear(); }
then you are using .NET Cache, your implementation will be something like
public class InMemoryCache : ICacheService { private int minutes = 15; public T Get<T>(string cacheID, Func<T> getItemCallback) where T : class { T item = HttpRuntime.Cache.Get(cacheID) as T; if (item == null) { item = getItemCallback(); HttpRuntime.Cache.Insert( cacheID, item, null, DateTime.Now.AddMinutes(minutes), System.Web.Caching.Cache.NoSlidingExpiration); } return item; } public void Clear() { IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator(); while (enumerator.MoveNext()) HttpRuntime.Cache.Remove(enumerator.Key.ToString()); } }
and you will use it like:
string cacheId = string.Concat("myinfo-", customer_id); MyInfo model = cacheProvider.Get<MyInfo>(cacheId, () => { MyInfo info = db.GetMyStuff(customer_id); return info; });
if you are using Memcached, all you have to do is create a new class that implements ICacheService and select the class you want using IoC or a direct call like:
private ICacheService cacheProvider; protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (cacheProvider == null) cacheProvider = new InMemoryCache(); base.Initialize(requestContext); }