When I load an ImageSource
from an Uri
, I can disable image caching by setting the CachingEnabled
property to false.
With an Image element in XAML
<Image x:Name="image"/>
the code below will load the image without any caching.
var imageUri = "https://www.google.de/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
image.Source = new UriImageSource
{
Uri = new Uri(imageUri),
CachingEnabled = false
};
Now I want to do the same with a StreamImageSource
:
var httpClient = new HttpClient();
image.Source = new StreamImageSource
{
Stream = async cancellationToken =>
{
var response = await httpClient.GetAsync(imageUri, cancellationToken);
return await response.Content.ReadAsStreamAsync(cancellationToken);
}
};
There seems to be no property to enable or disable caching, and I would not expect any caching at all. But on my Android device, the application writes image cache files to a folder named image_manager_disk_cache
in FileSystem.CacheDirectory
, which can be reproduced by
var imageCacheDirectory = Path.Combine(
FileSystem.CacheDirectory, "image_manager_disk_cache");
if (Directory.Exists(imageCacheDirectory))
{
foreach (var imageCacheFile in Directory.EnumerateFiles(imageCacheDirectory))
{
Debug.WriteLine(imageCacheFile);
}
}
Sample output is:
[0:] /data/user/0/com.companyname.imagecachetest/cache/image_manager_disk_cache/journal
[0:] /data/user/0/com.companyname.imagecachetest/cache/image_manager_disk_cache/5bcc99fe6930c85add40cfc486ae9a5a0451c08d71c6d3cd679ea26ec0293b9b.0
How can I disable this image caching for StreamImageSource?
Edit: My guess is that this caching is performed by the Glide
library, which is used by the imaging implementation of .NET MAUI on Android. I could however not find any information about how to disable Glide image caching in a MAUI application.