You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

305 lines
9.6 KiB

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Znyc.Cloudcar.Admin.Commons.Cache
{
/// <summary>
/// 缓存服务接口
/// </summary>
public interface ICacheService
{
#region 验证缓存项是否存在
/// <summary>
/// 验证缓存项是否存在
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
bool Exists(string key);
#endregion 验证缓存项是否存在
#region 添加缓存
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">缓存Value</param>
/// <returns></returns>
bool Add(string key, object value);
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">缓存Value</param>
/// <param name="expiresSliding">滑动过期时长(如果在过期时间内有操作,则以当前时间点延长过期时间)</param>
/// <param name="expiressAbsoulte">绝对过期时长</param>
/// <returns></returns>
bool Add(string key, object value, TimeSpan expiresSliding, TimeSpan expiressAbsoulte);
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">缓存Value</param>
/// <param name="expiresIn">缓存时长</param>
/// <param name="isSliding">是否滑动过期(如果在过期时间内有操作,则以当前时间点延长过期时间)</param>
/// <returns></returns>
bool Add(string key, object value, TimeSpan expiresIn, bool isSliding = false);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <param name="value"></param>
/// <returns></returns>
Task<bool> HashSetAsync(string key, string filed, object value);
/// <summary>
/// 添加缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">缓存Value</param>
/// <returns></returns>
Task<bool> AddAsync(string key, object value);
/// <summary>
/// /
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="expiresIn"></param>
/// <param name="isSliding"></param>
/// <returns></returns>
Task<bool> AddAsync(string key, object value, TimeSpan expiresIn, bool isSliding = false);
#endregion 添加缓存
#region 删除缓存
/// <summary>
/// 删除缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
bool Remove(string key);
/// <summary>
/// 批量删除缓存
/// </summary>
/// <param name="keys">缓存Key集合</param>
/// <returns></returns>
void RemoveAll(IEnumerable<string> keys);
/// <summary>
/// 使用通配符找出所有的key然后逐个删除
/// </summary>
/// <param name="pattern">通配符</param>
void RemoveByPattern(string pattern);
/// <summary>
/// 删除所有缓存
/// </summary>
void RemoveCacheAll();
/// <summary>
/// 删除缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
Task<bool> RemoveAsync(string key);
#endregion 删除缓存
#region 获取缓存
/// <summary>
/// 获取缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
T Get<T>(string key) where T : class;
/// <summary>
/// 获取缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <returns></returns>
object Get(string key);
/// <summary>
/// 获取缓存集合
/// </summary>
/// <param name="keys">缓存Key集合</param>
/// <returns></returns>
IDictionary<string, object> GetAll(IEnumerable<string> keys);
#endregion 获取缓存
#region 修改缓存
/// <summary>
/// 修改缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">新的缓存Value</param>
/// <returns></returns>
bool Replace(string key, object value);
/// <summary>
/// 修改缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">新的缓存Value</param>
/// <param name="expiresSliding">滑动过期时长(如果在过期时间内有操作,则以当前时间点延长过期时间)</param>
/// <param name="expiressAbsoulte">绝对过期时长</param>
/// <returns></returns>
bool Replace(string key, object value, TimeSpan expiresSliding, TimeSpan expiressAbsoulte);
/// <summary>
/// 修改缓存
/// </summary>
/// <param name="key">缓存Key</param>
/// <param name="value">新的缓存Value</param>
/// <param name="expiresIn">缓存时长</param>
/// <param name="isSliding">是否滑动过期(如果在过期时间内有操作,则以当前时间点延长过期时间)</param>
/// <returns></returns>
bool Replace(string key, object value, TimeSpan expiresIn, bool isSliding = false);
#endregion 修改缓存
#region Hash
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <param name="value"></param>
/// <returns></returns>
bool HSet(string key, string filed, object value);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <param name="value"></param>
/// <returns></returns>
Task<bool> HSetAsync(string key, string filed, object value);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
Task<bool> HMSetAsync(string key, object[] value);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
bool HMSet(string key, object[] value);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
string[] HMGet(string key, string[] filed);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
Task<string[]> HMGetAsync(string key, string filed);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
long HDel(string key, string[] filed);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
Task<long> HDelAsync(string key, string filed);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
bool HExists(string key, string filed);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
Task<bool> HExistsAsync(string key, string filed);
/// <summary>
/// 自增
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
Task<long> HIncrByAsync(string key, string filed);
/// <summary>
/// 自增
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
long HIncrBy(string key, string filed);
/// <summary>
/// 获取所有
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
Task<Dictionary<string, string>> HGetAllAsync(string key);
/// <summary>
/// 获取所有
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
Dictionary<string, string> HGetAll(string key);
/// <summary>
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <returns></returns>
Task<string> HGetAsync(string key, string filed);
/// <summary>
/// 设置一个键值对(不存在,则创建;否则,修改)
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <param name="value"></param>
/// <returns></returns>
Task<bool> HSetNxAsync(string key, string filed, object value);
/// <summary>
/// 设置一个键值对(不存在,则创建;否则,修改)
/// </summary>
/// <param name="key"></param>
/// <param name="filed"></param>
/// <param name="value"></param>
/// <returns></returns>
bool HSetNx(string key, string filed, object value);
#endregion
}
}