@@ -38,6 +38,7 @@ class ClusterCache {
3838
3939 this . allKeys = new Set ( )
4040 this . keyAccessTimes = new Map ( ) // Track access time for LRU eviction
41+ this . keyCreationTimes = new Map ( ) // Track creation time for age display
4142 this . keySizes = new Map ( ) // Track size of each cached value in bytes
4243 this . totalBytes = 0 // Track total cache size in bytes
4344 this . localCache = new Map ( )
@@ -78,11 +79,12 @@ class ClusterCache {
7879 */
7980 async get ( key ) {
8081 try {
81- const value = await this . clusterCache . get ( key , undefined )
82- if ( value !== undefined ) {
82+ const wrappedValue = await this . clusterCache . get ( key , undefined )
83+ if ( wrappedValue !== undefined ) {
8384 this . stats . hits ++
8485 this . keyAccessTimes . set ( key , Date . now ( ) ) // Update access time for LRU
85- return value
86+ // Unwrap the value from metadata
87+ return wrappedValue . data !== undefined ? wrappedValue . data : wrappedValue
8688 }
8789 if ( this . localCache . has ( key ) ) {
8890 this . stats . hits ++
@@ -153,10 +155,20 @@ class ClusterCache {
153155 clusterTotalBytes = await this . _getClusterTotalBytes ( )
154156 }
155157
156- await this . clusterCache . set ( key , value , this . ttl )
158+ // Wrap value with metadata including creation time
159+ const wrappedValue = {
160+ data : value ,
161+ createdAt : Date . now ( ) ,
162+ size : valueSize
163+ }
164+
165+ await this . clusterCache . set ( key , wrappedValue , this . ttl )
157166 this . stats . sets ++
158167 this . allKeys . add ( key )
159168 this . keyAccessTimes . set ( key , Date . now ( ) ) // Track access time
169+ if ( ! isUpdate ) {
170+ this . keyCreationTimes . set ( key , Date . now ( ) ) // Track creation time (only on new entries)
171+ }
160172 this . keySizes . set ( key , valueSize ) // Track size
161173 this . totalBytes += valueSize
162174 this . localCache . set ( key , value )
@@ -182,6 +194,9 @@ class ClusterCache {
182194 this . localCache . set ( key , value )
183195 this . allKeys . add ( key )
184196 this . keyAccessTimes . set ( key , Date . now ( ) )
197+ if ( ! isUpdate ) {
198+ this . keyCreationTimes . set ( key , Date . now ( ) )
199+ }
185200 this . keySizes . set ( key , valueSize )
186201 this . totalBytes += valueSize
187202 this . stats . sets ++
@@ -197,6 +212,7 @@ class ClusterCache {
197212 await this . clusterCache . delete ( key )
198213 this . allKeys . delete ( key )
199214 this . keyAccessTimes . delete ( key ) // Clean up access time tracking
215+ this . keyCreationTimes . delete ( key ) // Clean up creation time tracking
200216 const size = this . keySizes . get ( key ) || 0
201217 this . keySizes . delete ( key )
202218 this . totalBytes -= size
@@ -206,6 +222,7 @@ class ClusterCache {
206222 this . localCache . delete ( key )
207223 this . allKeys . delete ( key )
208224 this . keyAccessTimes . delete ( key ) // Clean up access time tracking
225+ this . keyCreationTimes . delete ( key ) // Clean up creation time tracking
209226 const size = this . keySizes . get ( key ) || 0
210227 this . keySizes . delete ( key )
211228 this . totalBytes -= size
@@ -223,6 +240,7 @@ class ClusterCache {
223240 await this . clusterCache . flush ( )
224241 this . allKeys . clear ( )
225242 this . keyAccessTimes . clear ( ) // Clear access time tracking
243+ this . keyCreationTimes . clear ( ) // Clear creation time tracking
226244 this . keySizes . clear ( ) // Clear size tracking
227245 this . totalBytes = 0
228246 this . localCache . clear ( )
@@ -245,6 +263,7 @@ class ClusterCache {
245263 this . localCache . clear ( )
246264 this . allKeys . clear ( )
247265 this . keyAccessTimes . clear ( ) // Clear access time tracking
266+ this . keyCreationTimes . clear ( ) // Clear creation time tracking
248267 this . keySizes . clear ( ) // Clear size tracking
249268 this . totalBytes = 0
250269 this . stats . evictions ++
0 commit comments