Image caching should be configurable for all ImageSources
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
When using StreamImageSource on Android, image cache files are written to a folder named `image_manager_disk_cache` in `FileSystem.CacheDirectory`.
Looking for a way to disable this behavior, I found that in `src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java` the methods [`loadImageFromFile`](https://github.com/dotnet/maui/blob/9ded53385880238b0edcf3b643bb25a548e43a1f/src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java#L242), [`loadImageFromStream`](https://github.com/dotnet/maui/blob/9ded53385880238b0edcf3b643bb25a548e43a1f/src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java#L261) and [`loadImageFromFont`](https://github.com/dotnet/maui/blob/9ded53385880238b0edcf3b643bb25a548e43a1f/src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java#L268) always pass `true` to the `cachingEnabled` argument of the [`loadInto`](https://github.com/dotnet/maui/blob/9ded53385880238b0edcf3b643bb25a548e43a1f/src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java#L232) method.
This seems wrong. Caching should be configurable, as it is implemented for loading an image from an URI string.
### Public API Changes
Add a `CachingEnabled` and a `CacheValidity` property to the classes `FileImageSource`, `StreamImageSource` and `FontImageSource`, similar to the respective properties in `UriImageSource`. Perhaps move those properties into their common base class.
Usage:
```csharp
var imageSource = new StreamImageSource
{
Stream = ...,
CachingEnabled = false
};
```
Alternatively, disable caching for those ImageSources. It seems pointless to cache an image file that is loaded from a local file or stream or font symbol.
### Intended Use-Case
In my map control library I am downloading map tiles images via HTTP from map content providers like OpenStreetMap or Bing Maps. It uses `StreamImageSource` to create `ImageSource` objects from the HTTP response stream or buffer.
The library implements its own map tile image caching mechanism and does not need any further caching.
Contributor guide
Research direction
Start in src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java by reading loadImageFromFile, loadImageFromStream, loadImageFromFont, and loadInto, then inspect the existing UriImageSource caching properties. Done means FileImageSource, StreamImageSource, and FontImageSource expose configurable CachingEnabled and CacheValidity behavior, or caching is intentionally disabled for them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- api, mobile-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100