public OperationResult GetCache(string KeyId) { if (KeyId != null || KeyId != "") { item = Mycache.GetCacheItem(KeyId); if (item.Equals(null)) { return new OperationResult(OperationResultType.Success, string.Format("成功取得{0}缓存值", KeyId), item.Value); } return new OperationResult(OperationResultType.QueryNull, string.Format("键{0}的缓存为空", KeyId)); } return new OperationResult(OperationResultType.ParamError, "KeyId is null"); }
public OperationResult SetCache(string KeyId, object obj, TimeSpan timespan) { if (KeyId != null || KeyId != "") { item = Mycache.GetCacheItem(KeyId); if (item.Equals(null)) { item = new CacheItem(KeyId, obj); policy.AbsoluteExpiration.Add(timespan); Mycache.Set(item, policy); return new OperationResult(OperationResultType.Success, string.Format("成功插入{0}缓存", KeyId)); } return new OperationResult(OperationResultType.NoChanged, string.Format("已存在{0}键的缓存", KeyId)); } return new OperationResult(OperationResultType.ParamError, "KeyId is null"); }