Wednesday 15 June 2011

asp.net - c# caching meta data content causes Index was outside the bounds of the array -



asp.net - c# caching meta data content causes Index was outside the bounds of the array -

on our application have class controls cache of info reused. have code year, lately, application (asp.net mvc 5) grows, giving error index outside bounds of array when attempting add together more info it. prepare restarting iis server.

how improve / modify code?

public class datacache { private static dictionary<string, cacheentry> _cacheentries = new dictionary<string, cacheentry>(); public static bool exists(string cacheid) { // check if cache entry valid. if (_cacheentries.containskey(cacheid) && datetime.utcnow < _cacheentries[cacheid].cacheuntil) homecoming true; homecoming false; } public static object get(string cacheid) { // homecoming entry. if (_cacheentries.containskey(cacheid)) homecoming _cacheentries[cacheid].data; else homecoming null; } public static void put(object cacheobj, string cacheid, datetime cacheuntil) { // create new cache entry. cacheentry e = new cacheentry() { info = cacheobj, cacheuntil = cacheuntil }; // delte pre-existing items. if (_cacheentries.containskey(cacheid)) _cacheentries.remove(cacheid); // insert cache. _cacheentries.add(cacheid, e); } class cacheentry { public object data; public datetime cacheuntil; } }

c# asp.net asp.net-mvc garbage-collection

No comments:

Post a Comment