@@ -134,28 +134,54 @@ public CacheStats getCacheStats(Object source, int setupid, int timepoint) {
134134 long totalSize = 0 ;
135135 long cellCount = 0 ;
136136
137- for (GlobalCacheKey key : cache .asMap ().keySet ()) {
138- if (timepoint == -1 ) {
139- // Match source for any timepoint
140- if (key .source .get () == source ) {
141- Object value = cache .getIfPresent (key );
142- if (value != null ) {
143- totalSize += getWeight (value );
144- cellCount ++;
137+ try {
138+ java .lang .reflect .Field tpField = bdv .img .cache .VolatileGlobalCellCache .Key .class
139+ .getDeclaredField ("timepoint" );
140+ tpField .setAccessible (true );
141+ java .lang .reflect .Field setupField = bdv .img .cache .VolatileGlobalCellCache .Key .class
142+ .getDeclaredField ("setup" );
143+ setupField .setAccessible (true );
144+
145+ for (GlobalCacheKey key : cache .asMap ().keySet ()) {
146+ bdv .img .cache .VolatileGlobalCellCache .Key innerKey = null ;
147+ if (key .key .get () instanceof bdv .img .cache .VolatileGlobalCellCache .Key ) {
148+ innerKey = (bdv .img .cache .VolatileGlobalCellCache .Key ) key .key .get ();
149+ }
150+ if (innerKey == null ) continue ;
151+
152+ int tp = (int ) tpField .get (innerKey );
153+ int setupId = (int ) setupField .get (innerKey );
154+
155+ if (timepoint == -1 ) {
156+ // Match source for any timepoint
157+ if ((key .getSource () == source ) && (setupid == setupId )) {
158+ Object value = cache .getIfPresent (key );
159+ if (value != null ) {
160+ totalSize += getWeight (value );
161+ cellCount ++;
162+ }
145163 }
146164 }
147- } else { // Match source and specific timepoint (any level)
148- if (key .getSource () == source && key .getTimepoint () == timepoint ) {
149- Object value = cache .getIfPresent (key );
150- if (value != null ) {
151- totalSize += getWeight (value );
152- cellCount ++;
153- }
154- }
155- }
156- }
165+ else {
166+ // Match source and specific timepoint (any level)
167+ if ((key .getSource () == source ) && (tp == timepoint ) && (setupid ==
168+ setupId ))
169+ {
170+ Object value = cache .getIfPresent (key );
171+ if (value != null ) {
172+ totalSize += getWeight (value );
173+ cellCount ++;
174+ }
175+ }
176+ }
177+ }
157178
158- return new CacheStats (cellCount , totalSize );
179+ return new CacheStats (cellCount , totalSize );
180+ }
181+ catch (Exception e ) {
182+ logger .debug ("Could not get cache stats: " + e .getMessage ());
183+ return new CacheStats (0 , 0 );
184+ }
159185 }
160186
161187}
0 commit comments