using System.Collections.Concurrent; using System.Net.Http; using System.Threading.Tasks; using Avalonia.Media.Imaging; namespace DownKyi.CustomControl.AsyncImageLoader.Loaders; public class RamCachedWebImageLoader : BaseWebImageLoader { private readonly ConcurrentDictionary> _memoryCache = new(); /// public RamCachedWebImageLoader() { } /// public RamCachedWebImageLoader(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClient) { } /// public override async Task ProvideImageAsync(string url) { var bitmap = await _memoryCache.GetOrAdd(url, LoadAsync).ConfigureAwait(false); // If load failed - remove from cache and return // Next load attempt will try to load image again if (bitmap == null) _memoryCache.TryRemove(url, out _); return bitmap; } }