public async Task <Unit> Handle(SaveUserPreferencesCommand request, CancellationToken cancellationToken) { await _userPreferencesDomainEntity.GetAsync(cancellationToken); _userPreferencesDomainEntity.MapFrom(request, _mapper); await _userPreferencesDomainEntity.UpsertAsync(cancellationToken); return(Unit.Value); }
public async Task <UserPreferences> GetAsync(bool refreshCache, CancellationToken cancellationToken) { var userId = _currentUser.Id; var cacheKey = $"{CacheKeyPrefix}/{userId}"; var cacheValue = await _cache.GetAsync(cacheKey, cancellationToken); if (refreshCache || cacheValue == null) { _userPreferencesDomainEntity.WithOptions(x => x.AsNoTracking = true); await _userPreferencesDomainEntity.GetAsync(cancellationToken); var userPreferences = _userPreferencesDomainEntity.Entity; var cacheEntryOptions = new DistributedCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromMinutes(10)); await _cache.SetAsync(cacheKey, Encode(userPreferences), cacheEntryOptions, cancellationToken); return(userPreferences); } else { return(Decode(cacheValue)); } }