@@ -2,9 +2,9 @@ import { FetchStore } from "zarrita";
2
2
import { AbsolutePath , AsyncMutable , Readable } from "@zarrita/storage" ;
3
3
4
4
import SubscribableRequestQueue from "../../utils/SubscribableRequestQueue" ;
5
- import VolumeCache from "../../VolumeCache" ;
6
5
7
6
import { SubscriberId } from "./types" ;
7
+ import { pathIsToMetadata } from "./utils" ;
8
8
9
9
type WrappedStoreOpts < Opts > = {
10
10
options ?: Opts ;
@@ -15,26 +15,17 @@ type WrappedStoreOpts<Opts> = {
15
15
16
16
/**
17
17
* `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`
19
19
*/
20
20
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 ) { }
22
22
// Dummy implementation to make this class easier to use in tests
23
23
set ( _key : AbsolutePath , _value : Uint8Array ) : Promise < void > {
24
24
return Promise . resolve ( ) ;
25
25
}
26
26
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
-
35
27
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 ) ) {
38
29
return this . baseStore . get ( key , opts ?. options ) ;
39
30
}
40
31
if ( opts ?. reportKey ) {
@@ -48,23 +39,17 @@ class WrappedStore<Opts, S extends Readable<Opts> = Readable<Opts>> implements A
48
39
49
40
const fullKey = keyPrefix + key . slice ( 1 ) ;
50
41
51
- // Check the cache
52
- const cacheResult = this . cache . get ( fullKey ) ;
53
- if ( cacheResult ) {
54
- return new Uint8Array ( cacheResult ) ;
55
- }
56
-
57
42
// Not in cache; load the chunk and cache it
58
43
if ( this . queue && opts ) {
59
44
return this . queue . addRequest (
60
45
fullKey ,
61
46
opts . subscriber ,
62
- ( ) => this . getAndCache ( key , fullKey , opts ?. options ) ,
47
+ async ( ) => this . baseStore . get ( key , opts ?. options ) ,
63
48
opts . isPrefetch
64
49
) ;
65
50
} else {
66
51
// 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 ) ;
68
53
}
69
54
}
70
55
}
0 commit comments