public void Clear() { using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()) { string[] fileNames = isolatedStorageFile.GetFileNames(this.cacheFileName); foreach (string fileName in fileNames) { if (fileName == this.cacheFileName) { isolatedStorageFile.DeleteFile(this.cacheFileName); break; } } } this.cachedItemDictionary = new IsolatedStorageCacheDictionary(); }
private void Load() { lock (SyncRoot) { if (this.CacheFileExists()) { IsolatedStorageFile isolatedStorageFile = null; IsolatedStorageFileStream isolatedStorageFileStream = null; StreamReader streamReader = null; try { isolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly(); isolatedStorageFileStream = new IsolatedStorageFileStream(this.cacheFileName, FileMode.Open, FileAccess.Read, FileShare.Read, isolatedStorageFile); XmlSerializer xs = new XmlSerializer(typeof(IsolatedStorageCacheDictionary)); streamReader = new StreamReader(isolatedStorageFileStream); this.cachedItemDictionary = (IsolatedStorageCacheDictionary)xs.Deserialize(streamReader); } finally { if (streamReader != null) { streamReader.Close(); } else if (isolatedStorageFileStream != null) { isolatedStorageFileStream.Close(); } else if (isolatedStorageFile != null) { isolatedStorageFile.Close(); } } } else { this.cachedItemDictionary = new IsolatedStorageCacheDictionary(); } } }