/// <summary> /// 设置模型到缓存 /// </summary> /// <param name="walletId"></param> /// <param name="walletInfo"></param> public void SetWalletInfo(string walletId, WalletViewModel walletInfo) { walletId.CheckNotNullOrEmpty(nameof(walletId)); walletInfo.CheckNotNull(nameof(walletInfo)); _cache.Add(CacheKeySupplier.WalletModelCacheKey(walletId), walletInfo); }
/// <summary> /// 获取信息 1缓存》2数据库 /// </summary> /// <param name="userId"></param> /// <returns></returns> public WalletViewModel GetWalletInfo(string walletId) { walletId.CheckNotNullOrEmpty(nameof(walletId)); var walletInfo = _cache.Get(CacheKeySupplier.WalletModelCacheKey(walletId)) as WalletViewModel; if (walletInfo == null) { walletInfo = _walletQueryService.Info(walletId.ToGuid()).ToWalletModel(); _cache.Add(CacheKeySupplier.WalletModelCacheKey(walletId), walletInfo); } return(walletInfo); }
/// <summary> /// 更新缓存 /// </summary> /// <param name="walletId"></param> /// <param name="walletInfo"></param> public void UpdateWalletInfo(string userId, WalletViewModel walletInfo) { _cache.Update(CacheKeySupplier.WalletModelCacheKey(userId), u => walletInfo); }