/// <summary> /// Remove a cached image from the cache /// </summary> /// <param name="result">The item to remove</param> public void RemoveCachedResult(CachedSearchResults result) { lock (threadLock) { CachedResults.Remove(result); } }
/// <summary> /// Adds a wallpaper to the cache /// </summary> /// <param name="wallpaper">Wallpaper to add</param> /// <param name="savedpath">The full path to the image file</param> public void AddCachedResults(Wallpaper wallpaper, string savedpath) { if (wallpaper == null || !File.Exists(savedpath)) { return; } if (CacheSize() > Settings.Instance.MaxCacheSize) { return; } lock (threadLock) { CachedSearchResults item; for (int i = 0; i < CachedResults.Count; i++) { item = CachedResults[i]; //If the wallpaper is already in the cache just refresh its age. //That way duplicates are avoided and if (item.Wallpaper.id == wallpaper.id) { item.ResultDate = DateTime.Now; return; } } CachedSearchResults newitem = new CachedSearchResults(); newitem.Path = savedpath; newitem.ResultDate = DateTime.Now; newitem.Wallpaper = wallpaper; CachedResults.Add(newitem); } }