| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace CarLocalMeter
- {
- /// <summary>
- /// 缓存接口
- /// </summary>
- public interface ICache
- {
- #region 设置缓存
- /// <summary>
- /// 设置缓存
- /// 注:默认过期类型为绝对过期
- /// </summary>
- /// <param name="key">主键</param>
- /// <param name="value">值</param>
- /// <param name="timeout">过期时间间隔</param>
- /// <param name="expireType">过期类型</param>
- void SetCache(string key, object value, int timeout = 0, ExpireType expireType = default);
- /// <summary>
- /// 设置键失效时间
- /// </summary>
- /// <param name="key">键值</param>
- /// <param name="expire">从现在起时间间隔</param>
- void SetKeyExpire(string key, int expire);
- #endregion
- #region 获取缓存
- /// <summary>
- /// 获取缓存
- /// </summary>
- /// <param name="key">主键</param>
- /// <typeparam name="T">数据类型</typeparam>
- T GetCache<T>(string key);
- #endregion
- #region 删除缓存
- /// <summary>
- /// 清除缓存
- /// </summary>
- /// <param name="key">主键</param>
- void RemoveCache(string key);
- #endregion
- }
- #region 类型定义
- /// <summary>
- /// 值信息
- /// </summary>
- public struct ValueInfoEntry
- {
- public string Value { get; set; }
- public string TypeName { get; set; }
- public int ExpireTime { get; set; }
- public ExpireType? ExpireType { get; set; }
- }
- /// <summary>
- /// 过期类型
- /// </summary>
- public enum ExpireType
- {
- /// <summary>
- /// 绝对过期
- /// 注:即自创建一段时间后就过期
- /// </summary>
- Absolute,
- /// <summary>
- /// 相对过期
- /// 注:即该键未被访问后一段时间后过期,若此键一直被访问则过期时间自动延长
- /// </summary>
- Relative,
- }
- #endregion
- }
|