OpenAuth.Net/Infrastructure/Cache/ObjCacheProvider.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2016-11-17 19:48:12 +08:00
// ***********************************************************************
2016-12-27 11:25:51 +08:00
// Assembly : Helper
// Author : Administrator
// Created : 12-21-2016
2016-11-17 19:48:12 +08:00
//
2016-12-27 11:25:51 +08:00
// Last Modified By : Administrator
// Last Modified On : 12-22-2016
2016-11-17 19:48:12 +08:00
// Contact :
2016-12-27 11:25:51 +08:00
// File: ObjCacheProvider.cs
2016-11-17 19:48:12 +08:00
// ***********************************************************************
2016-12-27 11:25:51 +08:00
2016-11-17 19:48:12 +08:00
using System;
2016-12-27 11:25:51 +08:00
namespace Infrastructure.Cache
2016-11-17 19:48:12 +08:00
{
/// <summary>
2016-12-27 11:25:51 +08:00
/// 缓存工厂实现
/// 这样做是方便换其他的缓存时如memcachedContext只换这一个地方即可
2016-11-17 19:48:12 +08:00
/// </summary>
public class ObjCacheProvider<T> : CacheProvider
{
public ObjCacheProvider()
{
2016-12-27 11:25:51 +08:00
SetCacheInstance(new CacheContext());
2016-11-17 19:48:12 +08:00
}
2016-12-27 11:25:51 +08:00
public bool Create(string key, T val, DateTime expire)
2016-11-17 19:48:12 +08:00
{
//设置缓存
2016-12-27 11:25:51 +08:00
return CacheContext.Set<T>(key, val, expire);
2016-11-17 19:48:12 +08:00
}
/// <summary>
/// 根据失效时间获取缓存
/// <para>李玉宝于2016-11-08 16:54:04</para>
/// </summary>
/// <param name="key">The key.</param>
public T GetCache(string key)
{
2016-12-27 11:25:51 +08:00
return CacheContext.Get<T>(key);
2016-11-17 19:48:12 +08:00
}
public void Remove(string key)
{
CacheContext.Remove(key);
}
}
}