Skip to content

Commit 084a553

Browse files
committed
Add loadTileMode info.
1 parent 7514e7f commit 084a553

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ extension ViewController : MKMapViewDelegate {
8383
}
8484

8585
```
86-
After setting up the map cache, browsed areas of the map will be kept on disk. If the user browses again, that area it will use the local version.
86+
After setting up the map cache, browsed areas of the map will be kept on disk. If the user browses again, that area it will use the local version without querying the server for that tile anymore.
8787

88-
Note that in the current version, the cache does not support expiration dates, so if you need to get an updated version of the tiles you must call `clear()` which will wipe out the whole cache.
88+
This may cause the tiles to be outdated if they change in the server. An alternative mode of working is to always query the server asking if there is a new tile and download it if so, or using the cached one if there were no changes. This can be done by setting the `config.loadTileMode = .serverThenCache`. See [LoadTileMode](https://www.merlos.org/MapCache/Enums/LoadTileMode.html) and [MapCacheConfig](https://www.merlos.org/MapCache/Structs/MapCacheConfig.html)
8989

90+
91+
92+
To empty the cache data:
9093
```swift
9194
mapCache.clear() {
9295
// do something after clear
@@ -97,7 +100,7 @@ mapCache.clear() {
97100
To get current cache size:
98101

99102
```swift
100-
mapCache.calculateDiskSize()
103+
mapCache.diskSize
101104
```
102105

103106
You can take a look at the [**Example/ folder**](https://github.com/merlos/MapCache/tree/master/Example/MapCache) to see a complete implementation.
@@ -165,6 +168,14 @@ config.capacity = 200 * 1024 * 1024 // 200 Megabytes
165168
// Default is `nil`, which uses the system temporary cache directory.
166169
config.baseURL = nil
167170

171+
// Sets the behavior of the cache:
172+
173+
// 1. .cacheThenServer (default): checks if the tile is in the cache, if not gets it from the server
174+
// 2. .serverThenCache: always checks with the server. If the tile is in the cache it is downloaded only if a new version is available.
175+
// 3. .cacheOnly: The offline mode. Does not produce traffic.
176+
// 4. .serverOnly: does not fallback to cache. Mostly for downloading
177+
178+
config.loadTileMode = .cacheThenServer
168179

169180
```
170181

0 commit comments

Comments
 (0)