-
缓存技术,封装好的缓存类
- 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;
- }
-
相关阅读:
Linux配置Java环境
Oracle的flashback特性之一:Flashback Query
Oracle的flashback特性之二:Flashback Table
吴恩达深度学习笔记 (补)1.1~1.5 神经网络概述
吴恩达深度学习笔记 2.10~2.18 向量化与python
吴恩达深度学习笔记 2.6~2.9 logistic中的梯度下降
吴恩达深度学习笔记 2.3 logistic回归损失
吴恩达深度学习笔记2.2 logistic回归
吴恩达深度学习笔记2.1 二分分类
[ubuntu]安装并使用python 3.6及与2.7的切换
-
原文地址:https://www.cnblogs.com/liuguanghai/p/4702104.html
Copyright © 2020-2023
润新知