/// <inheritdoc /> public string GetValue(string key) { using (var scope = _scopeProvider.CreateScope(autoComplete: true)) { return(_repository.Get(key)?.Value); } }
public bool Exist(TKey key) => dic.Write(d => { if (d.ContainsKey(key)) { return(d[key].HasOrigin); } var res = new MemoryKeyValueRepositoryValue <TValue>(); try { res.Value = _origin.Get(key); res.HasOrigin = true; } catch { res.Value = default(TValue); res.HasOrigin = false; } d.Add(key, res); return(res.HasOrigin); });
public void CanSetAndGet() { IScopeProvider provider = ScopeProvider; // Insert new key/value using (IScope scope = provider.CreateScope()) { var keyValue = new KeyValue { Identifier = "foo", Value = "bar", UpdateDate = DateTime.Now, }; IKeyValueRepository repo = CreateRepository(provider); repo.Save(keyValue); scope.Complete(); } // Retrieve key/value using (IScope scope = provider.CreateScope()) { IKeyValueRepository repo = CreateRepository(provider); IKeyValue keyValue = repo.Get("foo"); scope.Complete(); Assert.AreEqual("bar", keyValue.Value); } // Update value using (IScope scope = provider.CreateScope()) { IKeyValueRepository repo = CreateRepository(provider); IKeyValue keyValue = repo.Get("foo"); keyValue.Value = "buzz"; keyValue.UpdateDate = DateTime.Now; repo.Save(keyValue); scope.Complete(); } // Retrieve key/value again using (IScope scope = provider.CreateScope()) { IKeyValueRepository repo = CreateRepository(provider); IKeyValue keyValue = repo.Get("foo"); scope.Complete(); Assert.AreEqual("buzz", keyValue.Value); } }