Public classCachehelper {/// <summary> ///Create a file for a cache entry/// </summary> /// <param name= "key" >Cache Key</param> /// <param name= "obj" >Object Objects</param> Public Static voidInsert (stringKeyObjectobj) { //Create CacheHttpContext.Current.Cache.Insert (key, obj); } /// <summary> ///remove a file from a cache entry/// </summary> /// <param name= "key" >Cache Key</param> Public Static voidRemove (stringkey) { //Create CacheHttpContext.Current.Cache.Remove (key); } /// <summary> ///file dependencies for creating cache entries/// </summary> /// <param name= "key" >Cache Key</param> /// <param name= "obj" >Object Objects</param> /// <param name= "FileName" >File Absolute Path</param> Public Static voidInsert (stringKeyObjectObjstringfileName) { //To Create a cache dependencyCacheDependency dep =NewCacheDependency (fileName); //Create CacheHttpContext.Current.Cache.Insert (key, obj, DEP); } /// <summary> ///Create cache entry expires/// </summary> /// <param name= "key" >Cache Key</param> /// <param name= "obj" >Object Objects</param> /// <param name= "Expires" >expiry time (minutes)</param> Public Static voidInsert (stringKeyObjectObjintexpires) {HttpContext.Current.Cache.Insert (key, obj,NULL, Cache.noabsoluteexpiration,NewTimeSpan (0, Expires,0)); } /// <summary> ///Get Cache Object/// </summary> /// <param name= "key" >Cache Key</param> /// <returns>Object Objects</returns> Public Static ObjectGet (stringkey) { if(string. IsNullOrEmpty (key)) {return NULL; } returnHttpContext.Current.Cache.Get (key); } /// <summary> ///Get Cache Object/// </summary> /// <typeparam name= "T" >T Object</typeparam> /// <param name= "key" >Cache Key</param> /// <returns></returns> Public StaticT get<t> (stringkey) { Objectobj =Get (key); returnobj = =NULL?default(t): (t) obj; } }
Cache Caching Helper Classes