public void TestSetTextureForURLAtSizeLimit() { WebImageCache cache = WebImageCache.SharedCache; cache.SetMemorySizeLimit(80000); string urlA = "myimage.com/imageA"; string urlB = "myimage.com/imageB"; string urlC = "myimage.com/imageC"; var textureA = new Texture2D(100, 100); var textureB = new Texture2D(100, 100); var textureC = new Texture2D(100, 100); cache.SetTextureForURL(urlA, textureA, ""); cache.SetTextureForURL(urlB, textureB, ""); Assert.NotNull(cache.TextureResourceForURL(urlA)); Assert.NotNull(cache.TextureResourceForURL(urlB)); Assert.AreEqual(cache.EstimatedMemorySize, 80000); cache.SetTextureForURL(urlC, textureC, ""); // Make sure we're still at our limit and that url A got evicted. Assert.AreEqual(cache.EstimatedMemorySize, 80000); Assert.NotNull(cache.TextureResourceForURL(urlB)); Assert.NotNull(cache.TextureResourceForURL(urlC)); Assert.Null(cache.TextureResourceForURL(urlA)); }
public void TestChangingMemorySizeToLarger() { WebImageCache cache = WebImageCache.SharedCache; cache.SetMemorySizeLimit(80000); string urlA = "myimage.com/imageA"; string urlB = "myimage.com/imageB"; var textureA = new Texture2D(100, 100); var textureB = new Texture2D(100, 100); cache.SetTextureForURL(urlA, textureA, ""); cache.SetTextureForURL(urlB, textureB, ""); Assert.NotNull(cache.TextureResourceForURL(urlA)); Assert.NotNull(cache.TextureResourceForURL(urlB)); Assert.AreEqual(cache.EstimatedMemorySize, 80000); Assert.AreEqual(cache.MemorySizeLimit, 80000); cache.SetMemorySizeLimit(100000); // Check that nothing changed since we increased the limit. Assert.NotNull(cache.TextureResourceForURL(urlA)); Assert.NotNull(cache.TextureResourceForURL(urlB)); Assert.AreEqual(cache.EstimatedMemorySize, 80000); Assert.AreEqual(cache.MemorySizeLimit, 100000); }
public async Task <string> GetBackgroundImageAsync(string city, string weather) { var searchWeather = weather.Replace(" ", "+"); var cityBackground = await RepositoryManager.CityBackgroundRepository.GetItemAsync(city, searchWeather).ConfigureAwait(false); if (cityBackground == null) { var remoteImage = await GetAsync <CityBackground>($"api/images/{city}", requestMessage => { requestMessage.Headers.Add("key", "B50996A0-9D60-44AF-BF08-81029CE2B8C7"); }).ConfigureAwait(false); cityBackground = new CityBackground { Name = city, WeatherOverview = searchWeather, ImageUrl = remoteImage.ImageUrl }; await RepositoryManager.CityBackgroundRepository.InsertAsync(cityBackground).ConfigureAwait(false); } return(await WebImageCache.RetrieveImage(cityBackground.ImageUrl, $"{city}-{searchWeather}")); }
public async Task <string> GetImageAsync(string city, string weather, CancellationToken cancellationToken = default(CancellationToken)) { var searchWeather = weather.Replace(" ", "+"); var remoteImage = await GetAsync <CityWeatherImage>($"images/{city}?weather={searchWeather}", cancellationToken, SetApiKeyHeader).ConfigureAwait(false); var intermediaryDownloadUrl = $"{BaseApiUrl}images/downloads?imageUrl={remoteImage.ImageUrl.Split('?').FirstOrDefault()}&key={ApiKey}"; return(await WebImageCache.RetrieveImage(intermediaryDownloadUrl, $"{city}-{searchWeather}")); }
public void TestSetTextureForURL() { WebImageCache cache = WebImageCache.SharedCache; string mockURL = "myimage.com/image"; Texture2D mockTexture = new Texture2D(100, 100); cache.SetTextureForURL(mockURL, mockTexture, ""); Assert.NotNull(cache.TextureResourceForURL(mockURL)); Assert.AreEqual(cache.EstimatedMemorySize, 40000); }
public async Task <string> GetBackgroundImageAsync(string city, string weather) { var searchWeather = weather.Replace(" ", "+"); var remoteImage = await GetAsync <CityBackground>($"BackgroundByCityAndWeather?city={city}&weather={searchWeather}&height=1920").ConfigureAwait(false); var cityBackground = new CityBackground { Name = city, WeatherOverview = searchWeather, ImageUrl = remoteImage.ImageUrl }; return(await WebImageCache.RetrieveImage(cityBackground.ImageUrl, $"{city}-{searchWeather}")); }
public void TestReplaceTextureForURL() { WebImageCache cache = WebImageCache.SharedCache; cache.SetMemorySizeLimit(80000); string url = "myimage.com/image"; var textureA = new Texture2D(100, 100); var textureB = new Texture2D(100, 100); cache.SetTextureForURL(url, textureA, ""); Assert.AreEqual(cache.TextureResourceForURL(url).texture, textureA); cache.SetTextureForURL(url, textureB, ""); Assert.AreEqual(cache.TextureResourceForURL(url).texture, textureB); Assert.AreEqual(cache.EstimatedMemorySize, 40000); }
public void TestClearingCache() { WebImageCache cache = WebImageCache.SharedCache; string url = "myimage.com/imageA"; var texture = new Texture2D(100, 100); cache.SetTextureForURL(url, texture, ""); Assert.NotNull(cache.TextureResourceForURL(url)); Assert.AreEqual(cache.EstimatedMemorySize, 40000); cache.Clear(); Assert.IsNull(cache.TextureResourceForURL(url)); Assert.AreEqual(cache.EstimatedMemorySize, 0); }
public void TestChangingMemorySizeToSmaller() { WebImageCache cache = WebImageCache.SharedCache; cache.SetMemorySizeLimit(80000); string urlA = "myimage.com/imageA"; string urlB = "myimage.com/imageB"; var textureA = new Texture2D(100, 100); var textureB = new Texture2D(100, 100); cache.SetTextureForURL(urlA, textureA, ""); cache.SetTextureForURL(urlB, textureB, ""); Assert.NotNull(cache.TextureResourceForURL(urlA)); Assert.NotNull(cache.TextureResourceForURL(urlB)); Assert.AreEqual(cache.EstimatedMemorySize, 80000); Assert.AreEqual(cache.MemorySizeLimit, 80000); cache.SetMemorySizeLimit(50000); // Making the cache smaller by an image should evict the oldest one. Assert.IsNull(cache.TextureResourceForURL(urlA)); Assert.NotNull(cache.TextureResourceForURL(urlB)); Assert.AreEqual(cache.EstimatedMemorySize, 40000); Assert.AreEqual(cache.MemorySizeLimit, 50000); cache.SetMemorySizeLimit(0); // Making the cache zero should remove anything else! Assert.IsNull(cache.TextureResourceForURL(urlA)); Assert.IsNull(cache.TextureResourceForURL(urlB)); Assert.AreEqual(cache.EstimatedMemorySize, 0); Assert.AreEqual(cache.MemorySizeLimit, 0); }
public void TestInit() { WebImageCache cache = WebImageCache.SharedCache; Assert.AreEqual(cache.MemorySizeLimit, WebImageCache.DEFAULT_MEMORY_SIZE_LIMIT); }
public ImageDownload(WebImageCache c, string url) { this.cache = c; this.URL = url; www = new WWW(url); }