using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewLife.Caching
{
/// <summary>缓存</summary>
public abstract class Cache : ICache
{
#region 静态默认实现
/// <summary>默认缓存</summary>
public static ICache Default { get; set; } = new MyCache();
#endregion
#region 属性
/// <summary>名称</summary>
public String Name { get; protected set; }
/// <summary>获取和设置缓存,永不过期</summary>
/// <param name="key"></param>
/// <returns></returns>
public virtual Object this[String key] { get { return Get(key); } set { Add(key, value); } }
#endregion
#region 方法
/// <summary>是否包含缓存项</summary>
/// <param name="key"></param>
/// <returns></returns>
public abstract Boolean Contains(String key);
/// <summary>添加缓存项</summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
/// <param name="expire">过期时间,秒</param>
/// <returns></returns>
public abstract Boolean Add(String key, Object value, Int32 expire = 0);
/// <summary>添加获取缓存项</summary>
/// <param name="key">键</param>
/// <param name="value">值</param>
/// <param name="expire">过期时间,秒</param>
/// <returns></returns>
public abstract Object AddOrGet(String key, Object value, Int32 expire = 0);
/// <summary>获取缓存项</summary>
/// <param name="key">键</param>
/// <returns></returns>
public abstract Object Get(String key);
/// <summary>移除缓存项</summary>
/// <param name="key">键</param>
/// <returns></returns>
public abstract Object Remove(String key);
#endregion
}
}
|