MCPcopy Create free account
hub / github.com/echoVic/blade-code / getStats

Method getStats

src/context/storage/CacheStore.ts:180–212  ·  view source on GitHub ↗

* 获取缓存统计信息

()

Source from the content-addressed store, hash-verified

178 * 获取缓存统计信息
179 */
180 getStats(): {
181 size: number;
182 maxSize: number;
183 hitRate: number;
184 memoryUsage: number;
185 topKeys: { key: string; accessCount: number; lastAccess: number }[];
186 } {
187 this.cleanExpired();
188
189 let totalAccess = 0;
190 let memoryUsage = 0;
191 const keyStats: { key: string; accessCount: number; lastAccess: number }[] = [];
192
193 for (const [key, item] of Array.from(this.cache.entries())) {
194 totalAccess += item.accessCount;
195 memoryUsage += this.estimateItemSize(item);
196 keyStats.push({
197 key,
198 accessCount: item.accessCount,
199 lastAccess: item.lastAccess,
200 });
201 }
202
203 keyStats.sort((a, b) => b.accessCount - a.accessCount);
204
205 return {
206 size: this.cache.size,
207 maxSize: this.maxSize,
208 hitRate: totalAccess > 0 ? totalAccess / (totalAccess + this.cache.size) : 0,
209 memoryUsage,
210 topKeys: keyStats.slice(0, 10), // 返回前10个最常访问的键
211 };
212 }
213
214 /**
215 * 清理过期项

Callers

nothing calls this directly

Calls 2

cleanExpiredMethod · 0.95
estimateItemSizeMethod · 0.95

Tested by

no test coverage detected