private Dictionary <string, ICacheItem> Load(Stream s) { var table = new Dictionary <string, ICacheItem>(); int itemCount = UtilityMethods.ReadInt32(s); for (int i = 0; i < itemCount; i++) { try { string key = UtilityMethods.ReadString(s); ICacheItem val = persister.Read(s); if (val == null) // corrupt cache file { return(table); } table[key] = val; } catch (IOException) { return(table); } } return(table); }
public override ICacheItem Read(Stream inputStream) { string s = UtilityMethods.ReadString(inputStream); string response = UtilityMethods.ReadString(inputStream); string[] chunks = s.Split('\n'); // Corrupted cache record, so throw IOException which is then handled and returns partial cache. if (chunks.Length != 2) { throw new IOException("Unexpected number of chunks found"); } string url = chunks[0]; var creationTime = new DateTime(long.Parse(chunks[1], System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo)); var item = new ResponseCacheItem(new Uri(url), response, creationTime); return(item); }