using System;
using System.Collections.Generic;
namespace BP.GPM.DTalk.DDSDK
{
///
/// 简易缓存
///
public class SimpleCacheProvider : ICacheProvider
{
private static SimpleCacheProvider _instance = null;
#region GetInstance
///
/// 获取缓存实例
///
///
public static SimpleCacheProvider GetInstance()
{
if (_instance == null) _instance = new SimpleCacheProvider();
return _instance;
}
#endregion
private Dictionary _caches;
private SimpleCacheProvider()
{
this._caches = new Dictionary();
}
#region GetCache
///
/// 获取缓存
///
///
///
public object GetCache(string key)
{
object obj = this._caches.ContainsKey(key) ? this._caches[key].Expired() ? null : this._caches[key].Value : null;
return obj;
}
///
/// 获取缓存
///
///
///
///
public T GetCache(String key)
{
object obj = GetCache(key);
if (obj == null)
{
return default(T);
}
T result = (T)obj;
return result;
}
#endregion
#region SetCache
///
/// 设置缓存
///
///
///
///
public void SetCache(string key, object value, int expire = 300)
{
this._caches[key] = new CacheItem(key, value, expire);
}
#endregion
}
}