Using System;
Using System.Web;
Using System.Web.Caching;
Using System.Collections.Generic;
Using System.Collections;
Namespace Szrpp.common
{
<summary>
Cache-related action classes
</summary>
public class Datacache
{
<summary>
Gets the cache value of the current application specified CacheKey
</summary>
<param name= "CacheKey" ></param>
<returns></returns>
public static Object GetCache (String CacheKey)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
return Objcache[cachekey];
}
<summary>
Sets the cache value for the current application to specify CacheKey
</summary>
<param name= "CacheKey" ></param>
<param name= "Objobject" ></param>
public static void Setcache (String CacheKey, Object Objobject)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
if (objobject!=null)
Objcache.insert (CacheKey, objobject, NULL, DateTime.UtcNow.AddDays (7), TimeSpan.Zero);
}
<summary>
Sets the cache value for the current application to specify CacheKey
</summary>
<param name= "CacheKey" ></param>
<param name= "Objobject" ></param>
public static void Setcache (String CacheKey, Object Objobject, DateTime absoluteexpiration,timespan slidingexpiration)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
Objcache.insert (CacheKey, objobject,null,absoluteexpiration,slidingexpiration);
}
<summary>
Setting the cache based on dependencies
</summary>
<param name= "CacheKey" ></param>
<param name= "Objobject" ></param>
<param name= "CDEP" ></param>
<param name= "absoluteexpiration" ></param>
<param name= "slidingexpiration" ></param>
public static void Setcache (String CacheKey, Object Objobject, CacheDependency cdep, DateTime absoluteexpiration, Timespa n slidingexpiration)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
Objcache.insert (CacheKey, Objobject, CDEP, absoluteexpiration, slidingexpiration);
}
<summary>
Removes the cache value for the specified cachekey of the current application
</summary>
<param name= "CacheKey" ></param>
public static void RemoveCache (String CacheKey)
{
System.Web.Caching.Cache Objcache = Httpruntime.cache;
IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator ();
while (enumerator. MoveNext ())
{
if (enumerator. Key.tostring (). IndexOf (CacheKey, System.StringComparison.Ordinal) >= 0)
Objcache.remove (Enumerator. Key.tostring ());
}
}
<summary>
Remove all caches from the current application
</summary>
public static void RemoveCache ()
{
Retrieve Application Cache Enumerator
IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator ();
Copy all keys this currently exist in Cache
while (enumerator. MoveNext ())
{
HttpRuntime.Cache.Remove (Enumerator. Key.tostring ());
}
}
}
}
. NET self-caching mechanism instances