/// <summary> /// 更新缓存 /// </summary> /// <typeparam name="TCacheObject"></typeparam> /// <param name="redisManager"></param> /// <param name="redisDb"></param> /// <param name="key"></param> /// <param name="cacheObject"></param> /// <param name="exoireTime"></param> /// <returns></returns> public static async Task <TCacheObject> UpdateAsync <TCacheObject>( this RedisManager redisManager, EnumRedisDb redisDb, string key, TCacheObject cacheObject, DateTimeOffset exoireTime) { await redisManager.AddAsync(redisDb, key, cacheObject, exoireTime); return(await redisManager.GetAsync <TCacheObject>(redisDb, key)); }
/// <summary> /// 获取或添加缓存 /// </summary> /// <typeparam name="TCacheObject"></typeparam> /// <param name="redisDb"></param> /// <param name="key"></param> /// <param name="expireTime"></param> /// <param name="factory"></param> /// <param name="redisManager"></param> /// <returns></returns> public static async Task <TCacheObject> GetOrAddAsync <TCacheObject>( this RedisManager redisManager, EnumRedisDb redisDb, string key, DateTimeOffset expireTime, Func <TCacheObject> factory) { TCacheObject cacheObject; var result = await redisManager.GetAsync <TCacheObject>(redisDb, key); if (result == null) { cacheObject = factory.Invoke(); await redisManager.AddAsync(redisDb, key, cacheObject, expireTime); } else { cacheObject = result; } return(cacheObject); }