Open rachelkang opened 2 years ago
Adding a Clear() API could be nice but I think it isn't practical because it's a too big of a hammer. I think it's unlikely someone would want to clear all cached images.
For example, say the app has the user's profile image loaded. It's perfectly reasonable to cache it. But it's also perfectly reasonable to want to un-cache just that image so that an updated profile image could be loaded. You wouldn't want to clear out potentially thousands of cached items just to refresh one item.
I think to ship this with caching enabled by default, we must make some reasonable change to enable granular control of caching.
At this point I suggest either:
If (2) is too expensive (we don't have enough time, etc.), then I strongly urge doing (1) because I fear that the current behavior could be detrimental to a lot of apps. Everyone who finds an issue with caching will just have to disable it in lots of places, assuming they even understand why it's happening.
I am surprised this still hasn't been fixed, it has almost been a year since this issue got opened...
I am surprised this still hasn't been fixed, it has almost been a year since this issue got opened...
Due to lack of demand this issue has had a low priority. Can you share more info about the pattern you'd like to see for this? In your app do you want to clear all the image cache, or just one particular image? Or some other pattern? Knowing more about what users want will help us determine the best way to approach this issue.
I am surprised this still hasn't been fixed, it has almost been a year since this issue got opened...
Due to lack of demand this issue has had a low priority. Can you share more info about the pattern you'd like to see for this? In your app do you want to clear all the image cache, or just one particular image? Or some other pattern? Knowing more about what users want will help us determine the best way to approach this issue.
I am simply trying to not save an image in the cache, setting imagecaching to false does nothing, but I figured out I can set the CacheValidity to one minute does work unless you restart the app in less then a minute
Edit: Nvm, when you switch back and forth between a page that loads an image and another one a few times the app will stop loading and softlock
I'm creating this app with the possibility of rotating a picture. The picture is saved locally on the phone and rotated programatically, then saved to the same file. At this point caching on Android becomes an issue as it shows the old picture. I will investigate it an create a separate issue when I have some time.
Interesting that this is still an issue. Maui, Android 13, SDK 33, .Net 7.0
I have a graphics app that creates and makes changes to drawings and saves as bitmaps. The path to the bitmap is always saved on the drawing record in the local db. When a list loads the drawings, it binds the bitmap path to an image control. It only ever displays the original bitmap, never shows the changed/updated bitmap and yet when I export the same bitmap from the same path, I do get the amended image. But the list and image control won't let go of the cached file.
One would expect this to work:
if (File.Exists(drawing.ImagePath) == true) File.Delete(drawing.ImagePath);
//Then save using same path and file name once again:
using (var filestream = File.OpenWrite(drawing.ImagePath))
{
data.SaveTo(filestream);
filestream.Close();
}
This actually does save the changes. But the list and bound image control still sees the original (assume deleted but cached) file. This was never an issue with Xamarin Android apps. WHY has MS introduced this restriction? Sorry, no justification for it considering so many Xamarin apps are being ported over to Maui and THIS breaks things. Annoying and should not be the case.
What a useful library for Maui Apps and this Image caching debacle: https://github.com/Redth/FFImageLoading.Compat Hope that helps a few here!!
Install the nuget package the add this to the MauiProgram.cs:
.UseFFImageLoading()
Add this to the xaml page where you might have you Image control(s):
xmlns:ffimageloading="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Compat.Maui"
Substitute the Image xaml for this:
<ffimageloading:CachedImage CacheType="None" Source="{Binding ImagePath}" Aspect="AspectFit">
<ffimageloading:CachedImage.HeightRequest>
<OnIdiom x:TypeArguments="x:Double" Phone="200" Tablet="375" />
</ffimageloading:CachedImage.HeightRequest>
</ffimageloading:CachedImage>
Amend to suit you reqs...
Duplicate of https://github.com/dotnet/maui/issues/9773
Marking as a duplicate for linking reasons, but not a 100% duplicate. Configuration is closely related to clearing/deleting the cache.
Description
Currently, there are no APIs developers can leverage to clear the image cache and/or force an image to be retrieved from the original source (not from cache).
This should be further investigated, and if apt, the relevant APIs should be introduced. Whether this should be limited to images with URI sources should also be considered.
Public API Changes
Intended Use-Case
Give developers the capability to clear cache and/or force an image to be directly retrieved from the source more easily