Changeset 31611 in osm for applications


Ignore:
Timestamp:
2015-10-11T23:52:47+02:00 (9 years ago)
Author:
wiktorn
Message:

Fix missing tiles in cache, when tiles list is short (ex. low zoom level)

When there is small number of tiles that are fetched from MemoryTileCache
(smaller than size of the cache) - then they could be put multiple times in LRU
list although they were present only once in hash.

Now only move elements, when they are not present in hash.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/MemoryTileCache.java

    r31609 r31611  
    5252    public synchronized void addTile(Tile tile) {
    5353        CacheEntry entry = createCacheEntry(tile);
    54         hash.put(tile.getKey(), entry);
    55         lruTiles.addFirst(entry);
    56         if (hash.size() > cacheSize || lruTiles.getElementCount() > cacheSize) {
    57             removeOldEntries();
     54        if (hash.put(tile.getKey(), entry) == null) {
     55            // only if hash hadn't had the element, add it to LRU
     56            lruTiles.addFirst(entry);
     57            if (hash.size() > cacheSize || lruTiles.getElementCount() > cacheSize) {
     58                removeOldEntries();
     59            }
    5860        }
    5961    }
Note: See TracChangeset for help on using the changeset viewer.