public void IsThreadSafe() { var reads = 0; var cache = new BytesCache(); Parallel.For(0, 64, (idx) => { cache.Content("test", () => new byte[1] { 0xAA }); cache.Update("test", () => { reads++; return(new byte[1] { 0xBB }); }, () => { reads++; return(new byte[1] { 0xCC }); } ); cache.Content("test", () => { reads++; return(new byte[1] { 0xDD }); }); }); Assert.Equal(64, reads); }
public void CachesOnUpdate() { var reads = 0; var cache = new BytesCache(); cache.Content("test", () => new byte[1] { 0xAA }); cache.Update("test", () => { reads++; return(new byte[1] { 0xBB }); }, () => { reads++; return(new byte[1] { 0xCC }); } ); cache.Content("test", () => { reads++; return(new byte[1] { 0xDD }); }); Assert.Equal(1, reads); }