Repository navigation
Expand file tree
/
Copy pathcache.ts
More file actions
74 lines (66 loc) · 1.58 KB
/
Copy pathcache.ts
File metadata and controls
74 lines (66 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @file Linting cache management.
*/
import { type Diagnostic, LRUCache } from 'vscode-languageserver/node';
/**
* Maximum number of entries in the LRU cache.
*/
const CACHE_MAX_ENTRIES = 100;
/**
* Create a cache key for linting results.
*
* @param uri Document URI.
* @param aglintVersion AGLint version.
* @param documentVersion Document version (incremented on each change).
* @param configHash Hash of the linter config.
*
* @returns Cache key.
*/
export function createLintCacheKey(
uri: string,
aglintVersion: string,
documentVersion: number,
configHash: string,
): string {
return `${uri}:${aglintVersion}:${documentVersion}:${configHash}`;
}
/**
* Cache for linting results using LRU eviction strategy.
*/
export class LintingCache {
/**
* Internal LRU cache.
*/
private cache: LRUCache<string, Diagnostic[]>;
/**
* Creates a new linting cache.
*/
constructor() {
this.cache = new LRUCache<string, Diagnostic[]>(CACHE_MAX_ENTRIES);
}
/**
* Get cached diagnostics.
*
* @param key Cache key.
*
* @returns Cached diagnostics or undefined.
*/
public get(key: string): Diagnostic[] | undefined {
return this.cache.get(key);
}
/**
* Set cached diagnostics.
*
* @param key Cache key.
* @param diagnostics Diagnostics to cache.
*/
public set(key: string, diagnostics: Diagnostic[]): void {
this.cache.set(key, diagnostics);
}
/**
* Clear the cache.
*/
public clear(): void {
this.cache.clear();
}
}