private void CacheFlow(IPersonGetter cache) { setter.Store(defaultPerson); cache.GetPerson(defaultPerson.Id); setter.CleanUp(); try { getter.GetPerson(defaultPerson.Id); } catch (NotFoundException) { } catch (Exception) { Assert.True(false, "should fail with another exception"); } var p = cache.GetPerson(defaultPerson.Id); Assert.Equal(p.LastName, defaultPerson.LastName); }
public Person GetPerson(int id) { Person person; if (!_cache.TryGetValue(id, out person)) { person = _getter.GetPerson(id); _cache.Set(id, person); } return(person); }
public Person GetPerson(int id) { return(_cache.GetOrCreate(id, _ => _getter.GetPerson(id))); }