Skip to content

Commit 1c49b33

Browse files
committed
refactor: Implement LRU cache for folded content
- Replace ConcurrentHashMap with LinkedHashMap for foldedContentCache - Set maximum cache size to 10 entries - Implement removeEldestEntry to maintain LRU behavior
1 parent 55834b2 commit 1c49b33

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/kotlin/ai/devchat/plugin/completion/agent/ContextBuilder.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ data class CodeSnippet (
8080

8181
class ContextBuilder(val file: PsiFile, val offset: Int) {
8282
private val CURSOR_MARKER = "<<<CURSOR>>>"
83-
private val foldedContentCache = ConcurrentHashMap<Int, Pair<String, Int>>()
83+
private val MAX_FOLDED_CONTENT_CACHE_SIZE = 10 // 可以根据需要调整
84+
85+
private val foldedContentCache = object : LinkedHashMap<Int, Pair<String, Int>>(MAX_FOLDED_CONTENT_CACHE_SIZE, 0.75f, true) {
86+
override fun removeEldestEntry(eldest: Map.Entry<Int, Pair<String, Int>>): Boolean {
87+
return size > MAX_FOLDED_CONTENT_CACHE_SIZE
88+
}
89+
}
8490
private val foldCounter = AtomicInteger(0)
8591

8692
val filepath: String = file.virtualFile.path

0 commit comments

Comments
 (0)