{"id":15011622,"url":"https://github.com/soyfrien/imagecache","last_synced_at":"2025-10-08T22:30:25.373Z","repository":{"id":209949354,"uuid":"725320184","full_name":"soyfrien/ImageCache","owner":"soyfrien","description":"Save bandwidth or API calls by caching images in your .NET or .NET MAUI apps.","archived":false,"fork":false,"pushed_at":"2023-11-30T23:11:31.000Z","size":11182,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-16T00:13:57.417Z","etag":null,"topics":["cache-storage","image-caching","maui","nuget-package"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soyfrien.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-29T22:33:15.000Z","updated_at":"2025-01-18T16:48:12.000Z","dependencies_parsed_at":"2024-09-20T06:02:27.901Z","dependency_job_id":"f40c422a-81fd-46b6-b04b-a8792533cab2","html_url":"https://github.com/soyfrien/ImageCache","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":0.1923076923076923,"last_synced_commit":"9a6997d03e677da15ffa1d95c3e3e7351eee55ca"},"previous_names":["soyfrien/imagecache"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/soyfrien/ImageCache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyfrien%2FImageCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyfrien%2FImageCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyfrien%2FImageCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyfrien%2FImageCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soyfrien","download_url":"https://codeload.github.com/soyfrien/ImageCache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soyfrien%2FImageCache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000786,"owners_count":26082851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache-storage","image-caching","maui","nuget-package"],"created_at":"2024-09-24T19:41:21.337Z","updated_at":"2025-10-08T22:30:23.279Z","avatar_url":"https://github.com/soyfrien.png","language":"C#","readme":"# ImageCache\n-----------------------------------------\nThis library allows one to save bandwidth or API calls by caching images locally in a cache folder.\n\n## Video Demonstration\n![Demonstration GIF showing load times.](https://github.com/soyfrien/ImageCache/raw/main/ImageCacheDemo.gif)\n\n*Notice the instant load times for this CollectionView of web images.*\n\n\nFor .NET MAUI apps, the location of this folder is decided by [FileSystem.CacheDirectory](https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.storage.filesystem.cachedirectory), \nand for .NET 6.0 Windows apps, it is decided by [Environment.SpecialFolder.ApplicationData](https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-6.0#System_Environment_SpecialFolder_ApplicationData).\n\nThis version for .NET MAUI apps adds a new method to the `ImageCache` class, `GetAsImageSourceAsync(Uri uri)`, which returns an `ImageSource` instead of a `Stream`, `byte[]` or `Func\u003cStream\u003e`.\nThis is useful for binding to an `Image` control's `Source` property, which are often given a URI to a web resource.\n\nIn place of the URI, use `GetAsImageSourceAsync(Uri uri)` instead, which will remember if this URI has been cached before, and if so, return the cached image source instead of downloading it again.\n\nBecause it is derived from the general-purpose `ImageCache` class, it can also be used for other classes not specific to .NET MAUI, such as bitmaps, or other image types that can accept byte arrays or a `Stream`.\n\n# Usage\n-----------------------------------------\n* You can always set the cache folder by its public property. For .NET MAUI apps, the default is the `FileSystem.CacheDirectory` folder, and for .NET 6.0 Windows apps, it is the `Environment.SpecialFolder.ApplicationData` folder.\n\n* Use the **Purg()** method to clear the cache, the **GetAs...(Uri)** methods to retrieve images, and **GetByteCount(Uri)** if you need to check a remote images' filesize.\n* Some methods will let you pass in a string URL for convenience, but using Uris is preferred.\n* The **Save()** method does not need to be called. It will make sure the list of tracked Uris are saved to the cache. You may want to call if if you use **Clear()** on the list.\n* The **Restore()** method is obsolete, and does not need to be called.\n\n## Examples\n### Dependency Injection\nUse this class to cache images from the Internet. Its functions receive a URI and turn the resource into an `ImageSource`, byte array, `Stream`, or `Func‹Stream›`. Where ever you would give a control a URL, a stream, or byte[], do so as normal, but have ImageCache sit in the middle. For example, in .NET MAUI:\n```\n// MauiProgram.cs:\n...\nbuilder.Services.AddSingleton‹ImageCache›();\n...\n```\nThen use Dependency Injection to gain access to the class of a view, viewmodel, page or control. Assume a viewmodel has `Collection‹Image› Images` that will be used in a template:\n```\nUsing Ppdac.ImageCache.Maui;\nImageCache _imageCache;\n...\nPage(ViewModel viewModel, ImageCache imageCache)\n{\n\t_imageCache = imageCache;\n\tforeach (Image image in viewModel.Images)\n\t\tImage.Source = _imageCache.GetImageAsImageSource(image.Url);\n\t\n\tStream imageStream = await _imageCache.GetImageAsStreamAsync(image.Url);\n\tBitmap bitmap = new(imageStream);\n\t\n\tbyte[] imageBytes = await _imageCache.GetImageAsBytesAsync(image.Url);\n\t...\n```\n### Helper Helping Out However Examples\nWith the flexible IImage:\n```\n#if WINDOWS\n\t\tMicrosoft.Maui.Graphics.IImage? image = new W2DImageLoadingService().FromStream(await _imageCache.GetAsStreamAsync(new Uri(\"https://example.com/e.jpg\")));\n\t\t// Microsoft.Maui.Graphics.IImage? image = new W2DImageLoadingService().FromStream(_imageCache.GetAsStreamAsync(new Uri(\"https://example.com/e.jpg\")).Result);\n#elif IOS || ANDROID || MACCATALYST\n\t\tMicrosoft.Maui.Graphics.IImage image = PlatformImage.FromStream(_imageCache.GetAsStreamAsync(new Uri(\"https://example.com/e.jpg\")).Result);\n#endif\n```\n\nYou have an [Microsoft.Maui.Controls.Image](https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/image) that you currently pass a URL string into the `Source` property, instead of passing the string do something like:\n```\nSource = await ImageCache.GetAsImageSourceAsync(\"https://www.example.com/image.png\");\n// or ideally:\nSource = await ImageCache.GetAsImageSourceAsync(new Uri(\"https://www.example.com/image.png\"));\n```\n\nOr use the ImageSource type directly:\n```\nImageSource imageSource = await ImageCache.GetAsImageSourceAsync(imageUri);\nMicrosoft.Maui.Controls.Image mmcImage = new Microsoft.Maui.Controls.Image\n{\n\tSource = imageSource\n};\n```\n\nIt also works with controls that expect a byte array or stream, `System.Drawing.Image`, or the `Bitmap` class:\n```\nSystem.Drawing.Bitmap sdBitmap = new Bitmap(await _imageStore.GetAsStreamAsync(uri));\n\n// If you prefer synchronous methods:\nSystem.Drawing.Image sdImage = System.Drawing.Image.FromStream(_imageStore.GetAsStreamAsync(uri).Result);\n\n// Or just set up your byte array, and you can use these anywhere!\nbyte[] imageBytes = await _imageStore.GetAsByteArrayAsync(uri);\n```\n\nAs you can see, you are simply establishing a source for the image, but having a helper function sit right in the middle.\n\n### Other Usage\nYou may only want to use it on certain pages. There are several ways to do this, including with dependcy injection, as well as changing the default cache folder to whatever you like: \n```\n// Page A\n_imageCache.ImageCachePath = nameof(MyPage);\n\n// Page B\n_imageCacheB.ImageCachePath = nameof(MyOtherPage);\n```\n\nThough, DI is probably the best way to do this, injecting the class into the desired page.\n\n\n# Contibuting\n-----------------------------------------\nYou are actively encouraged to report bugs and contribute to this repository\n \nContributions Are Appreciated and Welcome\n\n* If you want to improve this library please make a pull request to: https://github.com/soyfrien/ImageCache/pulls\n\nBugs and Issues\n--------------------------------------------\n* Please report any issues you find, old or new: https://github.com/soyfrien/ImageCache/issues.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoyfrien%2Fimagecache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoyfrien%2Fimagecache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoyfrien%2Fimagecache/lists"}