File tree Expand file tree Collapse file tree 3 files changed +57
-4
lines changed Expand file tree Collapse file tree 3 files changed +57
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ import {
26
26
watchForComposerChanges ,
27
27
} from "./support/fileWatcher" ;
28
28
import { info } from "./support/logger" ;
29
- import { setParserBinaryPath } from "./support/parser" ;
29
+ import { clearParserCaches , setParserBinaryPath } from "./support/parser" ;
30
30
import { clearDefaultPhpCommand , initVendorWatchers } from "./support/php" ;
31
31
import { hasWorkspace , projectPathExists } from "./support/project" ;
32
32
import { cleanUpTemp } from "./support/util" ;
@@ -185,6 +185,7 @@ export function deactivate() {
185
185
}
186
186
187
187
disposeWatchers ( ) ;
188
+ clearParserCaches ( ) ;
188
189
189
190
if ( client ) {
190
191
client . stop ( ) ;
Original file line number Diff line number Diff line change
1
+ export class Cache < K , V > {
2
+ private maxSize : number ;
3
+ private cache : Map < K , V > ;
4
+
5
+ constructor ( maxSize : number ) {
6
+ this . maxSize = maxSize ;
7
+ this . cache = new Map ( ) ;
8
+ }
9
+
10
+ get ( key : K ) : V | undefined {
11
+ const value = this . cache . get ( key ) ;
12
+
13
+ if ( value !== undefined ) {
14
+ this . cache . delete ( key ) ;
15
+ this . cache . set ( key , value ) ;
16
+ }
17
+
18
+ return value ;
19
+ }
20
+
21
+ set ( key : K , value : V ) : void {
22
+ if ( this . cache . has ( key ) ) {
23
+ this . cache . delete ( key ) ;
24
+ } else if ( this . cache . size >= this . maxSize ) {
25
+ const firstKey = this . cache . keys ( ) . next ( ) . value ;
26
+
27
+ if ( firstKey !== undefined ) {
28
+ this . cache . delete ( firstKey ) ;
29
+ }
30
+ }
31
+
32
+ this . cache . set ( key , value ) ;
33
+ }
34
+
35
+ has ( key : K ) : boolean {
36
+ return this . cache . has ( key ) ;
37
+ }
38
+
39
+ clear ( ) : void {
40
+ this . cache . clear ( ) ;
41
+ }
42
+
43
+ size ( ) : number {
44
+ return this . cache . size ;
45
+ }
46
+ }
Original file line number Diff line number Diff line change @@ -9,14 +9,20 @@ import * as fs from "fs";
9
9
import * as os from "os" ;
10
10
import * as vscode from "vscode" ;
11
11
import { FeatureTag , ValidDetectParamTypes } from ".." ;
12
+ import { Cache } from "./cache" ;
12
13
import { showErrorPopup } from "./popup" ;
13
14
import { md5 , tempPath , toArray } from "./util" ;
14
15
15
- const currentlyParsing = new Map < string , Promise < AutocompleteResult > > ( ) ;
16
- const detected = new Map <
16
+ const currentlyParsing = new Cache < string , Promise < AutocompleteResult > > ( 100 ) ;
17
+ const detected = new Cache <
17
18
string ,
18
19
Promise < AutocompleteParsingResult . ContextValue [ ] >
19
- > ( ) ;
20
+ > ( 50 ) ;
21
+
22
+ export const clearParserCaches = ( ) : void => {
23
+ currentlyParsing . clear ( ) ;
24
+ detected . clear ( ) ;
25
+ } ;
20
26
21
27
type TokenFormatted = [ string , string , number ] ;
22
28
type Token = string | TokenFormatted ;
You can’t perform that action at this time.
0 commit comments