Skip to content

Commit

Permalink
fix: get refreshes keys in primary store
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Mar 11, 2024
1 parent 23e45a2 commit a716ee0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/datastore-core/src/tiered-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,21 @@ export class TieredLimitDatastore<T extends BaseDatastore, T2 extends BaseDatast
return key
}

/**
* If the key is in the primary store, remove it and add it to the back of the eviction order
*/
private refreshKeyEvictionOrder (key: Key): void {
const index = this.evictionOrder.indexOf(key)
if (index !== -1) {
this.evictionOrder.splice(index, 1) // Remove from eviction order
this.evictionOrder.push(key) // Add to end of eviction order
}
}

async get (key: Key, options?: AbortOptions): Promise<Uint8Array> {
if (await this.primaryStore.has(key)) {
log.trace('Getting %s from primary store', key.toString())
this.refreshKeyEvictionOrder(key)
return this.primaryStore.get(key, options)
}

Expand Down

0 comments on commit a716ee0

Please sign in to comment.