-
缓存技术,封装好的缓存类
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
-
- namespace Admin.Helper
- {
-
-
-
- public static class CacheHelper
- {
-
-
-
- private static System.Web.Caching.Cache ObjCache = System.Web.HttpRuntime.Cache;
-
- #region Exist方法
-
-
-
-
-
- public static bool Exist(string Key)
- {
- if (ObjCache[Key] == null)
- {
- return false;
- }
- return true;
- }
- #endregion
-
- #region Get方法
-
-
-
-
-
- public static Object Get(string Key)
- {
- object objkey = null;
- if (ObjCache[Key] != null)
- {
- objkey = ObjCache.Get(Key);
- }
- return objkey;
- }
- #endregion
-
- #region Set方法
-
-
-
-
-
-
-
- public static void Set(string Key, DateTime expiry, object obj)
- {
- if (ObjCache[Key] != null)
- {
- ObjCache.Remove(Key);
- }
-
- ObjCache.Insert(Key, obj, null, expiry, TimeSpan.Zero);
- }
-
-
-
-
-
-
-
- public static void Set(string Key, int min, object obj)
- {
- double douNum = double.Parse(min.ToString());
- Set(Key, DateTime.Now.AddMinutes(douNum), obj);
- }
- #endregion
-
- #region Del方法
-
-
-
-
-
- public static void Del(string Key)
- {
- if (ObjCache[Key] != null)
- {
- ObjCache.Remove(Key);
- }
- }
- #endregion
-
- #region 其他
-
-
-
-
- public static int Count
- {
- get
- {
- return ObjCache.Count;
- }
- }
-
-
-
-
- public static long PrivateBytes
- {
- get
- {
- return ObjCache.EffectivePrivateBytesLimit;
- }
- }
- #endregion
- }
- }
- 用方法如下:
-
-
-
-
-
- public static ProductDto GetProduct(string proId)
- {
- var key = "_ProductId" + proId;
-
- var cache = Helper.CacheHelper.Get(key);
- if (cache != null)
- {
- return (ProductDto)cache;
- }
- var pro = ServiceLocator.Create<IProductService>().Get(proId);
- if (pro == null) return new ProductDto();
- Helper.CacheHelper.Set(key, DateTime.Now.AddHours(8), pro);
- return pro;
- }
-
相关阅读:
机器学习作业(八)异常检测与推荐系统——Matlab实现
机器学习笔记(九)异常检测与推荐系统
Coursera 吴恩达 机器学习 学习笔记
机器学习作业(七)非监督学习——Matlab实现
机器学习笔记(八)非监督学习
图
希尔排序
霍纳算法的散列函数
javascript判断给定字符串是否是回文
JavaScript链表
-
原文地址:https://www.cnblogs.com/liuguanghai/p/4702104.html
Copyright © 2020-2023
润新知