纽威
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

3 years ago
  1. using System;
  2. using System.Collections;
  3. using System.Web;
  4. namespace NFine.Code
  5. {
  6. public class Cache : ICache
  7. {
  8. private static System.Web.Caching.Cache cache = HttpRuntime.Cache;
  9. public T GetCache<T>(string cacheKey) where T : class
  10. {
  11. if (cache[cacheKey] != null)
  12. {
  13. return (T)cache[cacheKey];
  14. }
  15. return default(T);
  16. }
  17. public void WriteCache<T>(T value, string cacheKey) where T : class
  18. {
  19. cache.Insert(cacheKey, value, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
  20. }
  21. public void WriteCache<T>(T value, string cacheKey, DateTime expireTime) where T : class
  22. {
  23. cache.Insert(cacheKey, value, null, expireTime, System.Web.Caching.Cache.NoSlidingExpiration);
  24. }
  25. public void RemoveCache(string cacheKey)
  26. {
  27. cache.Remove(cacheKey);
  28. }
  29. public void RemoveCache()
  30. {
  31. IDictionaryEnumerator CacheEnum = cache.GetEnumerator();
  32. while (CacheEnum.MoveNext())
  33. {
  34. cache.Remove(CacheEnum.Key.ToString());
  35. }
  36. }
  37. }
  38. }