11import * as zarr from "zarrita" ;
22import * as THREE from 'three' ;
3+ import QuickLRU from 'quick-lru' ;
34
45function GetZarrVariables ( obj : Record < string , { path ?: string ; kind ?: string } > ) {
56 //Parses out variables in a Zarr group for variable list
@@ -84,8 +85,6 @@ function parseUVCoords({normal,uv}:{normal:THREE.Vector3,uv:THREE.Vector2}){
8485 }
8586}
8687
87-
88-
8988export async function GetTimeSeries ( { TimeSeriesObject} :GetTimeSeries ) {
9089 const { uv, normal, variable, storePath} = TimeSeriesObject
9190 const d_store = zarr . tryWithConsolidated (
@@ -102,29 +101,31 @@ export async function GetTimeSeries({TimeSeriesObject}:GetTimeSeries){
102101 return arr
103102}
104103
104+
105105interface TimeSeriesInfo {
106106 uv :THREE . Vector2 ,
107107 normal :THREE . Vector3
108108}
109109
110+
110111export class ZarrDataset {
111112 private storePath : string ;
112113 private variable : string ;
113- private cache : { [ key : string ] : any } ;
114+ private cache : QuickLRU < string , any > ;
114115
115116 constructor ( storePath : string ) {
116117 this . storePath = storePath ;
117118 this . variable = "Default" ;
118- this . cache = { } ;
119+ this . cache = new QuickLRU ( { maxSize : 2000 } ) ;
119120 }
120121
121122 async GetArray ( variable : string ) {
122123 //This checks if variable is stored in cache
123124 this . variable = variable ;
124125 let outVar = null ;
125- if ( this . cache . hasOwnProperty ( variable ) ) {
126+ if ( this . cache . has ( variable ) ) {
126127 console . log ( "Using Cache" )
127- return this . cache [ variable ]
128+ return this . cache . get ( variable )
128129 }
129130 const d_store = zarr . tryWithConsolidated (
130131 new zarr . FetchStore ( this . storePath )
@@ -137,7 +138,7 @@ export class ZarrDataset{
137138 if ( outVar . is ( "number" ) || outVar . is ( "bigint" ) ) {
138139 const chunk = await zarr . get ( outVar )
139140 const typedArray = new Float32Array ( chunk . data ) ;
140- this . cache [ variable ] = chunk ;
141+ this . cache . set ( variable , chunk ) ;
141142 // TypeScript will now infer the correct numeric type
142143 return {
143144 data : typedArray ,
@@ -151,10 +152,10 @@ export class ZarrDataset{
151152
152153 async GetTimeSeries ( TimeSeriesInfo :TimeSeriesInfo ) {
153154 const { uv, normal} = TimeSeriesInfo
154- if ( ! this . cache [ this . variable ] ) {
155+ if ( ! this . cache . has ( this . variable ) ) {
155156 return [ 0 ]
156157 }
157- const { data, shape, stride} = this . cache [ this . variable ]
158+ const { data, shape, stride} = this . cache . get ( this . variable )
158159 //This is a complicated logic check but it works bb
159160 const sliceSize = parseUVCoords ( { normal, uv} )
160161
0 commit comments