New to Telerik UI for Silverlight? Download free 30-day trial

Tiles Cache

RadMap allows you to cache the tile images downloaded by the map provider.

The tiles caching is disabled by default. To enable it, set the IsTileCachingEnabled property of the map provider to True. The default cache storage is the file system and the original location should look something like this: C:\Users\<username>\AppData\Local\TelerikMapCache\OpenStreetMapProvider

RadMap providers use the FileSystemCache class to enable the tiles caching. Additionally, there are two more built-in caching implementations - MemoryCache and IsolatedStorageCache - which can be set via the CacheStorage property of the provider.

FileSystemCache

FileSystemCache saves the requested tiles to the file system and more specifically to the ApplicationData folder on the OS: C:\Users\<username>\AppData\Local\TelerikMapCache\<providername>. This type of cache allows you to define few settings like max size of the storage, an expiration date-time for the tiles and also the file system directory where the tiles are saved.

Example 1: Setting FileSystemCache and changing the default path

<telerik:RadMap> 
    <telerik:RadMap.Provider> 
        <telerik:OpenStreetMapProvider IsTileCachingEnabled="True"> 
            <telerik:OpenStreetMapProvider.CacheStorage> 
                <telerik:FileSystemCache CachePath="C:\temp\OSMCache" /> 
            </telerik:OpenStreetMapProvider.CacheStorage> 
        </telerik:OpenStreetMapProvider> 
    </telerik:RadMap.Provider> 
</telerik:RadMap>    

MemoryCache

MemoryCache saves each tile in a byte array stored in memory.

Example 2: Replacing the default FileSystemCache with MemoryCache

<telerik:RadMap> 
    <telerik:RadMap.Provider> 
        <telerik:OpenStreetMapProvider IsTileCachingEnabled="True"> 
            <telerik:OpenStreetMapProvider.CacheStorage> 
                <telerik:MemoryCache /> 
            </telerik:OpenStreetMapProvider.CacheStorage> 
        </telerik:OpenStreetMapProvider> 
    </telerik:RadMap.Provider> 
</telerik:RadMap>    

IsolatedStorageCache

IsolatedStorageCache saves the requested tiles into the isolated storage.

Example 3: Replacing the default FileSystemCache with IsolatedStorageCache

<telerik:RadMap> 
    <telerik:RadMap.Provider> 
        <telerik:OpenStreetMapProvider IsTileCachingEnabled="True"> 
            <telerik:OpenStreetMapProvider.CacheStorage> 
                <telerik:IsolatedStorageCache /> 
            </telerik:OpenStreetMapProvider.CacheStorage> 
        </telerik:OpenStreetMapProvider> 
    </telerik:RadMap.Provider> 
</telerik:RadMap>    

Custom Cache Storage

Besides the built-in cache storages, a custom storage can be created by implementing the ICacheStorage interface. This allows to introduce a saving mechanism different then the originally provided ones. The interface requests to implement Load, LoadAsync and Save methods.

Example 4: Creating custom cache storage

public class CustomCacheStorage : ICacheStorage 
{ 
    public Stream Load(string fileName) 
    { 
        // Load the tile using the 'fileName' as an unique identifier to retrieve the corresponding tile. 
    } 
 
    public void LoadAsync(string fileName, Action<byte[]> callback) 
    { 
        // Load the tile (a byte array) using the 'fileName' as an unique identifier to retrieve the corresponding tile. 
        // Pass it to the callback that will be called to return a tile if it is available. 
 
        // callback(tile); 
    } 
 
    public void Save(string fileName, DateTime expirationDate, byte[] tile) 
    { 
        // Save the tile using: 
        // the 'fileName' as an unique identifier,  
        // the 'expirationDate' as the date until when the tile will be cached and 
        // the 'tile' as the body of the tile image 
    } 
} 

Example 5: Using the custom cache storage

<telerik:RadMap> 
    <telerik:RadMap.Provider> 
        <telerik:OpenStreetMapProvider IsTileCachingEnabled="True"> 
            <telerik:OpenStreetMapProvider.CacheStorage> 
                <local:CustomCacheStorage /> 
            </telerik:OpenStreetMapProvider.CacheStorage> 
        </telerik:OpenStreetMapProvider> 
    </telerik:RadMap.Provider> 
</telerik:RadMap>    

Request Cache Level

The RadMap control uses the built-in .NET caching mechanism for downloading map tiles. The tiled providers expose a RequestCacheLevel property which is used to control the current caching level. The default level is System.Net.Cache.RequestCacheLevel.CacheIfAvailable.

Example 6: Setting the RequestCacheLevel

<telerik:RadMap> 
    <telerik:RadMap.Provider> 
        <telerik:OpenStreetMapProvider RequestCacheLevel="Revalidate" /> 
    </telerik:RadMap.Provider> 
</telerik:RadMap>    

See Also

In this article
Not finding the help you need? Improve this article