public async ValueTask <Account> LoadOrCreateAsync(string id) { if (!_cache.TryGetValue(id, out var account)) { account = await _db.GetOrCreateAccountAsync(id); _cache.AddOrUpdate(account); } return(account); }
public async ValueTask <Account> LoadOrCreateAsync(string id) { var account1 = await _db.GetOrCreateAccountAsync(id); if (!_cache.TryGetValue(id, out var account)) { _cache.AddOrUpdate(account1); } if (!account1.Equals(account)) { account = await _db.Update(account1.ExternalId, account); } return(account); }
public async Task UpdateAccount() { //Update account in cache, don't bother saving to DB, this is not an objective of this task. var account = await Get(); account.Counter++; _accountCache.AddOrUpdate(account); }
public AccountService(IAccountCache cache, IAccountDatabase db) { _cache = cache; _db = db; _db.GetAccountsOnce().ForEach( account => _cache.AddOrUpdate(account) ); }