gitconnected staff @gitconnected
4

Getting started with Image Caching in .NET MAUI

Getting started with Image Caching in .NET MAUI

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 article: Spanish post: https://es.askxammy.com/almacenamiento-de-imagenes-en-cache-en-net-maui/ References: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/image?view=net-maui-7.0?WT.mc_id=DT-MVP-50033

askxammy.com