public class MemoryTileCache extends java.lang.Object implements TileCache
TileCache
implementation that stores all Tile
objects in
memory up to a certain limit (getCacheSize()
). If the limit is
exceeded the least recently used Tile
objects will be deleted.Modifier and Type | Class and Description |
---|---|
protected static class |
MemoryTileCache.CacheEntry
Linked list element holding the
Tile and links to the
MemoryTileCache.CacheEntry.next and MemoryTileCache.CacheEntry.prev item in the list. |
protected static class |
MemoryTileCache.CacheLinkedListElement
Special implementation of a double linked list for
MemoryTileCache.CacheEntry
elements. |
Modifier and Type | Field and Description |
---|---|
protected int |
cacheSize
Default cache size
|
protected java.util.Map<java.lang.String,MemoryTileCache.CacheEntry> |
hash |
protected static java.util.logging.Logger |
log |
protected MemoryTileCache.CacheLinkedListElement |
lruTiles
List of all tiles in their last recently used order
|
Constructor and Description |
---|
MemoryTileCache() |
Modifier and Type | Method and Description |
---|---|
void |
addTile(Tile tile)
Adds a tile to the cache.
|
void |
clear()
Clears the cache deleting all tiles from memory
|
protected MemoryTileCache.CacheEntry |
createCacheEntry(Tile tile) |
int |
getCacheSize() |
Tile |
getTile(TileSource source,
int x,
int y,
int z)
Retrieves a tile from the cache if present, otherwise
null
will be returned. |
int |
getTileCount() |
protected void |
removeEntry(MemoryTileCache.CacheEntry entry) |
protected void |
removeOldEntries()
Removes the least recently used tiles
|
void |
setCacheSize(int cacheSize)
Changes the maximum number of
Tile objects that this cache holds. |
protected static final java.util.logging.Logger log
protected int cacheSize
protected final java.util.Map<java.lang.String,MemoryTileCache.CacheEntry> hash
protected final MemoryTileCache.CacheLinkedListElement lruTiles
public void addTile(Tile tile)
TileCache
TileCache.getTile(TileSource, int, int, int)
is unspecified and depends on the
implementation.public Tile getTile(TileSource source, int x, int y, int z)
TileCache
null
will be returned.getTile
in interface TileCache
source
- the tile sourcex
- tile number on the x axis of the tile to be retrievedy
- tile number on the y axis of the tile to be retrievedz
- zoom level of the tile to be retrievednull
if the tile is not
present in the cacheprotected void removeOldEntries()
protected void removeEntry(MemoryTileCache.CacheEntry entry)
protected MemoryTileCache.CacheEntry createCacheEntry(Tile tile)
public void clear()
public int getTileCount()
getTileCount
in interface TileCache
public int getCacheSize()
public void setCacheSize(int cacheSize)
Tile
objects that this cache holds.cacheSize
- new maximum number of tiles