Use IDistributedCache

This commit is contained in:
ClemensFischer 2024-02-03 21:46:17 +01:00
parent 24850446e7
commit 1dc0352a08
2 changed files with 7 additions and 14 deletions

View file

@ -30,28 +30,21 @@ which define the currently displayed map viewport.
--- ---
The WPF version allows to use a System.Runtime.Caching.ObjectCache instance for caching map tile bitmaps. The library allows to use a Microsoft.Extensions.Caching.Distributed.IDistributedCache instance for caching map tile bitmaps.
The cache may be set to an instance of System.Runtime.Caching.MemoryCache (e.g. MemoryCache.Default),
but caching can also be done persistently by some specialized ObjectCache implementation.
Map Control comes with three such implementations: Map Control comes with three such implementations:
* ImageFileCache, an ObjectCache implementation that stores each cached map tile as a single image file, * ImageFileCache, an IDistributedCache implementation that stores each cached map tile as a single image file,
in the original file format delivered by the map provider (typically PNG or JPG). ImageFileCache is part of in the original file format delivered by the map provider (typically PNG or JPG). ImageFileCache is part of
the MapControl.WPF library. It does not support expiration, which means that cached tile image files will the MapControl library.
not be deleted automatically. The cache may hence consume a considerable amount of disk space. * FileDbCache, an IDistributedCache implementation based on [EzTools FileDb](https://github.com/eztools-software/FileDb),
* FileDbCache, an ObjectCache implementation based on [EzTools FileDb](https://github.com/eztools-software/FileDb),
a simple, file based No-SQL database, in a separate library FileDbCache.WPF. a simple, file based No-SQL database, in a separate library FileDbCache.WPF.
* SQLiteCache, an ObjectCache implementation based on [System.Data.SQLite](https://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki), * SQLiteCache, an IDistributedCache implementation based on [System.Data.SQLite](https://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki),
in a separate library SQLiteCache.WPF. in a separate library SQLiteCache.WPF.
If you want to try the sample application with persistent caching, uncomment the appropriate TileImageLoader.Cache If you want to try the sample application with persistent caching, uncomment the appropriate TileImageLoader.Cache
setting in the sample application's MainWindow.xaml.cs file. Please note that some map providers may not allow setting in the sample application's MainWindow.xaml.cs file. Please note that some map providers may not allow
persistent caching of their map data. persistent caching of their map data.
For UWP and WinUI, the cache functionality is defined by the interface IImageCache in the namespace MapControl.Caching,
and implemented by the classes ImageFileCache, FileDbCache (in library FileDbCache.UWP/.WinUI) and SQLiteCache
(in library SQLiteCache.UWP/.WinUI).
Local image files and database files are written to ApplicationData.Current.TemporaryFolder by default.
--- ---
XAML Map Control is available on NuGet, with Package Id [XAML.MapControl](https://www.nuget.org/packages/XAML.MapControl/). XAML Map Control is available on NuGet, with Package Id [XAML.MapControl](https://www.nuget.org/packages/XAML.MapControl/).

View file

@ -16,7 +16,7 @@ namespace SampleApplication
{ {
static MainWindow() static MainWindow()
{ {
TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder); //TileImageLoader.Cache = new ImageFileCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder); //TileImageLoader.Cache = new FileDbCache(TileImageLoader.DefaultCacheFolder);
//TileImageLoader.Cache = new SQLiteCache(TileImageLoader.DefaultCacheFolder); //TileImageLoader.Cache = new SQLiteCache(TileImageLoader.DefaultCacheFolder);