public class FileSystemTileCache extends java.lang.Object implements TileCache
FileSystemTileCache
caches tiles in a dedicated path in the file system, specified in the constructor.
When used for a TileRendererLayer
, persistent caching may result in clipped
labels when tiles from different instances are used. To work around this, either display labels in a separate
LabelLayer
(experimental) or disable persistence as described in
FileSystemTileCache(int, File, GraphicFactory, boolean)
.
Note: previously the FileSystemTileCache utilized threading to speed up response times. This is not the
case anymore and the constructors have been removed.Constructor and Description |
---|
FileSystemTileCache(int capacity,
java.io.File cacheDirectory,
org.mapsforge.core.graphics.GraphicFactory graphicFactory)
Compatibility constructor that creates a non-threaded, non-persistent FSTC.
|
FileSystemTileCache(int capacity,
java.io.File cacheDirectory,
org.mapsforge.core.graphics.GraphicFactory graphicFactory,
boolean persistent)
Creates a new FileSystemTileCache.
|
Modifier and Type | Method and Description |
---|---|
void |
addObserver(Observer observer) |
boolean |
containsKey(Job key) |
void |
destroy()
Destroys this cache.
|
org.mapsforge.core.graphics.TileBitmap |
get(Job key) |
int |
getCapacity() |
int |
getCapacityFirstLevel() |
org.mapsforge.core.graphics.TileBitmap |
getImmediately(Job key)
Returns tileBitmap only if available at fastest cache in case of multi-layered cache, null otherwise.
|
boolean |
isPersistent()
Whether the cache is persistent.
|
void |
purge()
Purges this cache.
|
void |
put(Job key,
org.mapsforge.core.graphics.TileBitmap bitmap) |
void |
removeObserver(Observer observer) |
void |
setWorkingSet(java.util.Set<Job> workingSet)
Reserves a working set in this cache, for multi-level caches this means bringing the elements in workingSet into
the fastest cache.
|
public FileSystemTileCache(int capacity, java.io.File cacheDirectory, org.mapsforge.core.graphics.GraphicFactory graphicFactory)
capacity
- the maximum number of entries in this cache.cacheDirectory
- the directory where cached tiles will be stored.graphicFactory
- the graphicFactory implementation to use.java.lang.IllegalArgumentException
- if the capacity is negative.public FileSystemTileCache(int capacity, java.io.File cacheDirectory, org.mapsforge.core.graphics.GraphicFactory graphicFactory, boolean persistent)
persistent
argument to specify whether cache contents should be kept across instances. A
persistent cache will serve any tiles it finds in cacheDirectory
. Calling destroy()
on a
persistent cache will not delete the cache directory. Conversely, a non-persistent cache will serve only tiles
added to it via the put(Job, TileBitmap)
method, and calling destroy()
on a non-persistent
cache will delete cacheDirectory
.capacity
- the maximum number of entries in this cache.cacheDirectory
- the directory where cached tiles will be stored.graphicFactory
- the graphicFactory implementation to use.persistent
- if cache data will be kept between instancesjava.lang.IllegalArgumentException
- if the capacity is negative.java.lang.IllegalArgumentException
- if the capacity is negative.public boolean containsKey(Job key)
containsKey
in interface TileCache
Map.containsKey(java.lang.Object)
public void destroy()
purge()
. If the cache is
persistent, it does nothing.
Beginning with 0.5.1, accessing the cache after calling destroy()
is discouraged. In order to empty the
cache and force all tiles to be re-rendered or re-requested from the source, use purge()
instead.
Earlier versions lacked the purge()
method and used destroy()
instead, but this practice is now
discouraged and may lead to unexpected results when used with features introduced in 0.5.1 or later.public org.mapsforge.core.graphics.TileBitmap get(Job key)
public int getCapacity()
getCapacity
in interface TileCache
public int getCapacityFirstLevel()
getCapacityFirstLevel
in interface TileCache
public org.mapsforge.core.graphics.TileBitmap getImmediately(Job key)
TileCache
getImmediately
in interface TileCache
public boolean isPersistent()
public void purge()
get(Job)
issued after purging will not return any tiles added before the purge operation.
Purging will also delete the cache directory on disk, freeing up disk space.
Applications should purge the tile cache when map model parameters change, such as the render style for locally
rendered tiles, or the source for downloaded tiles. Applications which frequently alternate between a limited
number of map model configurations may want to consider using a different cache for each.public void put(Job key, org.mapsforge.core.graphics.TileBitmap bitmap)
public void setWorkingSet(java.util.Set<Job> workingSet)
TileCache
setWorkingSet
in interface TileCache
public void addObserver(Observer observer)
addObserver
in interface ObservableInterface
public void removeObserver(Observer observer)
removeObserver
in interface ObservableInterface