Skip to content

Commit

Permalink
Tile Cache Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
BiologyTools committed Apr 20, 2024
1 parent b074bdc commit d828b55
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Source/Bio/ISlideSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ public LruCache(int capacity)

public TValue Get(Info key)
{
if (cacheMap.TryGetValue(key, out var node))
foreach (LinkedListNode<(Info key, TValue value)> item in cacheMap.Values)
{
lruList.Remove(node);
lruList.AddLast(node);
Info tf = (Info)node.Value.key;
Info k = item.Value.key;
if(k.Coordinate == key.Coordinate && k.Index == key.Index)
{
lruList.Remove(item);
lruList.AddLast(item);
return item.Value.value;
}
}
return default(TValue);
}
Expand Down Expand Up @@ -74,20 +78,26 @@ public TileCache(SlideSourceBase source, int capacity = 500)

public async Task<byte[]> GetTile(TileInformation info)
{

byte[] data = cache.Get(info);
LruCache<TileInformation, byte[]>.Info inf = new LruCache<TileInformation, byte[]>.Info();
inf.Coordinate = info.Coordinate;
inf.Index = info.Index;
byte[] data = cache.Get(inf);
if (data != null)
{
return data;
}
byte[] tile = await LoadTile(info);
if(tile!=null)
AddTile(info, tile);
return tile;
}

private void AddTile(TileInformation tileId, byte[] tile)
{
cache.Add(tileId, tile);
LruCache<TileInformation, byte[]>.Info inf = new LruCache<TileInformation, byte[]>.Info();
inf.Coordinate = tileId.Coordinate;
inf.Index = tileId.Index;
cache.Add(inf, tile);
}

private async Task<byte[]> LoadTile(TileInformation tileId)
Expand Down

0 comments on commit d828b55

Please sign in to comment.