You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
using System;
|
|
using System.Collections;
|
|
using System.Web;
|
|
|
|
|
|
namespace NFine.Code
|
|
{
|
|
public class Cache : ICache
|
|
{
|
|
private static System.Web.Caching.Cache cache = HttpRuntime.Cache;
|
|
|
|
public T GetCache<T>(string cacheKey) where T : class
|
|
{
|
|
if (cache[cacheKey] != null)
|
|
{
|
|
return (T)cache[cacheKey];
|
|
}
|
|
return default(T);
|
|
}
|
|
public void WriteCache<T>(T value, string cacheKey) where T : class
|
|
{
|
|
cache.Insert(cacheKey, value, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
|
|
}
|
|
public void WriteCache<T>(T value, string cacheKey, DateTime expireTime) where T : class
|
|
{
|
|
cache.Insert(cacheKey, value, null, expireTime, System.Web.Caching.Cache.NoSlidingExpiration);
|
|
}
|
|
public void RemoveCache(string cacheKey)
|
|
{
|
|
cache.Remove(cacheKey);
|
|
}
|
|
public void RemoveCache()
|
|
{
|
|
IDictionaryEnumerator CacheEnum = cache.GetEnumerator();
|
|
while (CacheEnum.MoveNext())
|
|
{
|
|
cache.Remove(CacheEnum.Key.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|