Have you ever wondered how to cache images in your app? .NET MAUI already includes this functionality! In this article, we will quickly learn how to use it and adapt it to our specific needs.
The explanation will be divided into the following points:
๐น How does image caching work?
๐น Learning about its structure
๐น Properties available
Letโs start!
How does image caching work?
In .NET MAUI, downloaded images are cached by default for one day. This functionality is in action whenever you download an image from a URL.
Let’s learn about its structure:
Properties available
You can experiment with different values using the properties provided by the UriImageSource
class. Letโs explore each one of these properties:
๐น URL: The URI of the image is provided, allowing it to be downloaded for display โ It receives a Uri as value.
๐น CachingEnabled: Determines whether the image cache is enabled or disabled. – It receives a Bool data type and its default value is True.
๐น CacheValidity: The value entered here will decide how long the image is saved on the local device. Keep in mind that the default value is set with one day as value. โ It receives a TimeSpan as value.
โ If you send a single number, it will be interpreted as the number of days you want the cache to store the data. Since this property is of type TimeSpan, you can format it in XAML and pass a value like this:
Now that we understand the structure and properties, let’s dive into the code implementation:
And done!! ๐ From now on, you are ready to works your Images with cache .NET MAUI I hope you like it! ๐๐
<Label Text=โThanks for ready!ย ๐ โ />ย
Spanish post:
References:
3 thoughts on “Getting started with Image Caching in .NET MAUI”