/// <summary> /// Loads the cache file to populate the in memory cache. /// </summary> private void LoadCache() { lock (SyncRoot) { SQLContext.CreateDatabase(); Dictionary <string, CachedImage> dictionary = SQLContext.GetImages(); foreach (KeyValuePair <string, CachedImage> pair in dictionary) { this.Add(pair); } } }
/// <summary> /// Saves the in memory cache to the file-system. /// </summary> /// <param name="key"> /// The key. /// </param> /// <param name="cachedImage"> /// The cached Image. /// </param> /// <param name="remove"> /// The remove. /// </param> /// <returns> /// true, if the dictionary is saved to the file-system; otherwise, false. /// </returns> private async Task <int> SaveCacheAsync(string key, CachedImage cachedImage, bool remove) { try { if (remove) { return(await SQLContext.RemoveImageAsync(cachedImage)); } return(await SQLContext.AddImageAsync(cachedImage)); } catch { return(0); } }