public void CachesOnUpdate() { var reads = 0; var cache = new XmlCache(); cache.Content("test", () => new XDocument(new XElement("splashy"))); cache.Update("test", () => { reads++; return(new XDocument(new XElement("splashy"))); }, () => { reads++; return(new XDocument(new XElement("splashy"))); } ); cache.Content("test", () => { reads++; return(new XDocument(new XElement("splashy"))); }); Assert.Equal(1, reads); }
public void IsThreadSafe() { var reads = 0; var cache = new XmlCache(); Parallel.For(0, 64, (idx) => { cache.Content("test", () => new XDocument(new XElement("splashy"))); cache.Update("test", () => { reads++; return(new XDocument(new XElement("splashy"))); }, () => { reads++; return(new XDocument(new XElement("splashy"))); } ); cache.Content("test", () => { reads++; return(new XDocument(new XElement("splashy"))); }); }); Assert.Equal(64, reads); }