📄 ExpiringCache¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 3 |
| 🧱 Classes | 1 |
| 📦 Imports | 1 |
| 📊 Variables & Constants | 2 |
| 📐 Interfaces | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/typescript-estree/src/parseSettings/ExpiringCache.ts
📦 Imports¶
| Name | Source |
|---|---|
CacheDurationSeconds |
@typescript-eslint/types |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
DEFAULT_TSCONFIG_CACHE_DURA... |
30 |
const | 30 |
✓ |
ZERO_HR_TIME |
[number, number] |
const | [0, 0] |
✗ |
Functions¶
ExpiringCache.clear(): void¶
Returns: void
Calls:
this.#map.clear
ExpiringCache.get(key: Key): Value | undefined¶
Parameters:
keyKey
Returns: Value | undefined
Calls:
this.#map.getprocess.hrtimethis.#map.delete
Internal Comments:
Code
get(key: Key): Value | undefined {
const entry = this.#map.get(key);
if (entry?.value != null) {
if (this.#cacheDurationSeconds === 'Infinity') {
return entry.value;
}
const ageSeconds = process.hrtime(entry.lastSeen)[0];
if (ageSeconds < this.#cacheDurationSeconds) {
// cache hit woo!
return entry.value;
}
// key has expired - clean it up to free up memory
this.#map.delete(key);
}
// no hit :'(
return undefined;
}
ExpiringCache.set(key: Key, value: Value): this¶
Parameters:
keyKeyvalueValue
Returns: this
Calls:
this.#map.setprocess.hrtime
Code
Classes¶
ExpiringCache¶
A map with key-level expiration.
Implements: CacheLike<Key, Value>
Class Code
export class ExpiringCache<Key, Value> implements CacheLike<Key, Value> {
readonly #cacheDurationSeconds: CacheDurationSeconds;
readonly #map = new Map<
Key,
Readonly<{
lastSeen: [number, number];
value: Value;
}>
>();
constructor(cacheDurationSeconds: CacheDurationSeconds) {
this.#cacheDurationSeconds = cacheDurationSeconds;
}
clear(): void {
this.#map.clear();
}
get(key: Key): Value | undefined {
const entry = this.#map.get(key);
if (entry?.value != null) {
if (this.#cacheDurationSeconds === 'Infinity') {
return entry.value;
}
const ageSeconds = process.hrtime(entry.lastSeen)[0];
if (ageSeconds < this.#cacheDurationSeconds) {
// cache hit woo!
return entry.value;
}
// key has expired - clean it up to free up memory
this.#map.delete(key);
}
// no hit :'(
return undefined;
}
set(key: Key, value: Value): this {
this.#map.set(key, {
lastSeen:
this.#cacheDurationSeconds === 'Infinity'
? // no need to waste time calculating the hrtime in infinity mode as there's no expiry
ZERO_HR_TIME
: process.hrtime(),
value,
});
return this;
}
}
Methods (3) — full entries under Functions
| Method | Signature |
|---|---|
clear |
(): void |
get |
(key: Key): Value \| undefined |
set |
(key: Key, value: Value): this |
Interfaces¶
CacheLike<Key, Value>¶
Interface Code
Generated by Syntax Scribe