rename Cache to SharedPromiseCache and make Cache interface

This commit is contained in:
Brandon Liu
2022-10-04 11:07:08 +08:00
parent 93ff392e6f
commit 6d6e931f1d
2 changed files with 22 additions and 11 deletions

View File

@@ -370,11 +370,22 @@ function deserializeIndex(buffer: ArrayBuffer): Entry[] {
export class VersionMismatch extends Error {}
export interface Cache {
getHeader: (source: Source) => Promise<Header>;
getDirectory: (
source: Source,
offset: number,
length: number,
header: Header
) => Promise<Entry[]>;
invalidate: (source: Source) => void;
}
// a "dumb" bag of bytes.
// only caches headers and directories
// deduplicates simultaneous responses
// (estimates) the maximum size of the cache.
export class Cache {
export class SharedPromiseCache {
cache: Map<string, CacheEntry>;
sizeBytes: number;
maxSizeBytes: number;
@@ -526,7 +537,7 @@ export class PMTiles {
if (cache) {
this.cache = cache;
} else {
this.cache = new Cache();
this.cache = new SharedPromiseCache();
}
}