Improved cache reporting

- Fix count of saved entries
- Catch and report errors on save and restore
- Correctly report entries that are never requested
This commit is contained in:
Daz DeBoer 2022-08-16 15:29:23 -06:00
parent cbebff71e9
commit b49446f8e1
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
4 changed files with 24 additions and 10 deletions

View file

@ -62,11 +62,11 @@ export class CacheEntryListener {
requestedRestoreKeys: string[] | undefined
restoredKey: string | undefined
restoredSize: number | undefined
notRestored: string | undefined
savedKey: string | undefined
savedSize: number | undefined
unsaved: string | undefined
notSaved: string | undefined
constructor(entryName: string) {
this.entryName = entryName
@ -88,6 +88,11 @@ export class CacheEntryListener {
return this
}
markNotRestored(message: string): CacheEntryListener {
this.notRestored = message
return this
}
markSaved(key: string, size: number | undefined): CacheEntryListener {
this.savedKey = key
this.savedSize = size
@ -100,8 +105,8 @@ export class CacheEntryListener {
return this
}
markUnsaved(message: string): CacheEntryListener {
this.unsaved = message
markNotSaved(message: string): CacheEntryListener {
this.notSaved = message
return this
}
}
@ -166,9 +171,15 @@ function renderEntryDetails(listener: CacheListener): string {
}
function getRestoredMessage(entry: CacheEntryListener, cacheWriteOnly: boolean): string {
if (entry.notRestored) {
return `(Entry not restored: ${entry.notRestored})`
}
if (cacheWriteOnly) {
return '(Entry not restored: cache is write-only)'
}
if (entry.requestedKey === undefined) {
return '(Entry not restored: not requested)'
}
if (entry.restoredKey === undefined) {
return '(Entry not restored: no match found)'
}
@ -179,8 +190,8 @@ function getRestoredMessage(entry: CacheEntryListener, cacheWriteOnly: boolean):
}
function getSavedMessage(entry: CacheEntryListener, cacheReadOnly: boolean): string {
if (entry.unsaved) {
return `(Entry not saved: ${entry.unsaved})`
if (entry.notSaved) {
return `(Entry not saved: ${entry.notSaved})`
}
if (entry.savedKey === undefined) {
if (cacheReadOnly) {
@ -198,7 +209,7 @@ function getCount(
cacheEntries: CacheEntryListener[],
predicate: (value: CacheEntryListener) => number | undefined
): number {
return cacheEntries.filter(e => predicate(e) !== undefined).length
return cacheEntries.filter(e => predicate(e)).length
}
function getSize(