developmentseed / developmentseed/deck.gl-raster

COG tile caching with IndexedDB

Open
#167 5 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
228
Forks
29
Avg merge
12h 27m
Merged PRs (30d)
4

Description

Browsers normally cache GET requests, but this **does not apply for range requests**. When visualizing COG files, every time you pan into an area, you fetch those tiles again. (Note that the deck.gl TileLayer [separately has a memory cache](https://deck.gl/docs/api-reference/geo-layers/tile-layer#maxcachesize)).

We should implement (optional) disk caching of tile requests with [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API).

IndexedDB has an async API, making it perfect to use inside of `getTileData`. We can create a cache key based on the input file + COG x, y, z index. Then inside of `getTileData` we can attempt to load the key from the cache. If it's missing, we can fetch the tile again.

Pseudocode:
```ts
async function getTileData(
cache: CogTileCache,
image: GeoTIFFImage,
key: TileKey
): Promise {
const cached = await cache.get(key);
if (cached) return cached;

// geotiff.js call (example)
const rasters = await image.readRasters({
window: image.getTileWindow(key.x, key.y),
interleave: true,
});

await cache.put(key, tile);
return tile;
}
```

- We'll want a user-facing option for whether to enable the cache at all.
- User-facing option for maximum size in bytes of the cache
- Option for eviction strategy? LRU by default.

Note that Zarr should be generally unaffected by this because most Zarr implementations will save each Zarr chunk as an individual file. So browsers should cache Zarr chunk requests normally.

Ref https://chatgpt.com/share/695ee39e-cab0-8008-8e00-380f1f9c600c

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.