Skip to content

Commit 9ef4d06

Browse files
committed
remove caching from WrappedStore
1 parent 000089f commit 9ef4d06

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

src/loaders/zarr_utils/CachingArray.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Array, ArrayMetadata, Chunk, DataType } from "@zarrita/core";
22
import VolumeCache, { CacheData } from "../../VolumeCache";
33
import { AbsolutePath, Readable } from "@zarrita/storage";
4+
import { pathIsToMetadata } from "./utils";
45

56
const ZARR_EXTS = [".zarray", ".zgroup", ".zattrs", "zarr.json"];
67

@@ -12,7 +13,7 @@ export default class CachingArray<T extends DataType, Store extends Readable = R
1213
}
1314

1415
async getChunk(coords: number[], opts?: Parameters<Store["get"]>[1]): Promise<Chunk<T>> {
15-
if (!this.cache || ZARR_EXTS.some((s) => this.path.endsWith(s))) {
16+
if (!this.cache || pathIsToMetadata(this.path)) {
1617
return super.getChunk(coords, opts);
1718
}
1819

src/loaders/zarr_utils/WrappedStore.ts

+6-21
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { FetchStore } from "zarrita";
22
import { AbsolutePath, AsyncMutable, Readable } from "@zarrita/storage";
33

44
import SubscribableRequestQueue from "../../utils/SubscribableRequestQueue";
5-
import VolumeCache from "../../VolumeCache";
65

76
import { SubscriberId } from "./types";
7+
import { pathIsToMetadata } from "./utils";
88

99
type WrappedStoreOpts<Opts> = {
1010
options?: Opts;
@@ -15,26 +15,17 @@ type WrappedStoreOpts<Opts> = {
1515

1616
/**
1717
* `Readable` is zarrita's minimal abstraction for any source of data.
18-
* `WrappedStore` wraps another `Readable` and adds (optional) connections to `VolumeCache` and `RequestQueue`.
18+
* `WrappedStore` wraps another `Readable` and adds useful extras, notably an (optional) connection to `RequestQueue`
1919
*/
2020
class WrappedStore<Opts, S extends Readable<Opts> = Readable<Opts>> implements AsyncMutable<WrappedStoreOpts<Opts>> {
21-
constructor(private baseStore: S, private cache?: VolumeCache, private queue?: SubscribableRequestQueue) {}
21+
constructor(private baseStore: S, private queue?: SubscribableRequestQueue) {}
2222
// Dummy implementation to make this class easier to use in tests
2323
set(_key: AbsolutePath, _value: Uint8Array): Promise<void> {
2424
return Promise.resolve();
2525
}
2626

27-
private async getAndCache(key: AbsolutePath, cacheKey: string, opts?: Opts): Promise<Uint8Array | undefined> {
28-
const result = await this.baseStore.get(key, opts);
29-
if (this.cache && result) {
30-
this.cache.insert(cacheKey, result);
31-
}
32-
return result;
33-
}
34-
3527
async get(key: AbsolutePath, opts?: WrappedStoreOpts<Opts> | undefined): Promise<Uint8Array | undefined> {
36-
const ZARR_EXTS = [".zarray", ".zgroup", ".zattrs", "zarr.json"];
37-
if (!this.cache || ZARR_EXTS.some((s) => key.endsWith(s))) {
28+
if (pathIsToMetadata(key)) {
3829
return this.baseStore.get(key, opts?.options);
3930
}
4031
if (opts?.reportKey) {
@@ -48,23 +39,17 @@ class WrappedStore<Opts, S extends Readable<Opts> = Readable<Opts>> implements A
4839

4940
const fullKey = keyPrefix + key.slice(1);
5041

51-
// Check the cache
52-
const cacheResult = this.cache.get(fullKey);
53-
if (cacheResult) {
54-
return new Uint8Array(cacheResult);
55-
}
56-
5742
// Not in cache; load the chunk and cache it
5843
if (this.queue && opts) {
5944
return this.queue.addRequest(
6045
fullKey,
6146
opts.subscriber,
62-
() => this.getAndCache(key, fullKey, opts?.options),
47+
async () => this.baseStore.get(key, opts?.options),
6348
opts.isPrefetch
6449
);
6550
} else {
6651
// Should we ever hit this code? We should always have a request queue.
67-
return this.getAndCache(key, fullKey, opts?.options);
52+
return this.baseStore.get(key, opts?.options);
6853
}
6954
}
7055
}

src/loaders/zarr_utils/utils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export function getSourceChannelNames(src: ZarrSource): string[] {
1818
return Array.from({ length }, (_, idx) => `Channel ${idx + src.channelOffset}`);
1919
}
2020

21+
const META_FILENAMES = [".zarray", ".zgroup", ".zattrs", "zarr.json"];
22+
export const pathIsToMetadata = (path: string): boolean => META_FILENAMES.some((s) => path.endsWith(s));
23+
2124
/** Turns `axesTCZYX` into the number of dimensions in the array */
2225
export const getDimensionCount = ([t, c, z]: TCZYX<number>) => 2 + Number(t > -1) + Number(c > -1) + Number(z > -1);
2326

0 commit comments

Comments
 (0)