Skip to content

Commit 55834b2

Browse files
committed
feat: Optimize cache management in IDEUtils
- Reduce MAX_CACHE_SIZE from 1000 to 100 - Introduce MAX_FOLD_CACHE_SIZE constant set to 100 - Replace ConcurrentHashMap with LinkedHashMap for foldCache
1 parent dbf1f07 commit 55834b2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/kotlin/ai/devchat/common/IDEUtils.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import com.intellij.psi.SmartPsiElementPointer
3131

3232

3333
object IDEUtils {
34-
private const val MAX_CACHE_SIZE = 1000
34+
private const val MAX_CACHE_SIZE = 100
35+
private const val MAX_FOLD_CACHE_SIZE = 100 // 可以根据需要调整
36+
3537
private data class CacheEntry(val filePath: String, val offset: Int, val element: SoftReference<SymbolTypeDeclaration>)
3638

3739
private val variableCache = object : LinkedHashMap<String, CacheEntry>(MAX_CACHE_SIZE, 0.75f, true) {
@@ -48,8 +50,11 @@ object IDEUtils {
4850
val elementHash: Int
4951
)
5052

51-
private val foldCache = ConcurrentHashMap<String, SoftReference<FoldCacheEntry>>()
52-
53+
private val foldCache = object : LinkedHashMap<String, SoftReference<FoldCacheEntry>>(MAX_FOLD_CACHE_SIZE, 0.75f, true) {
54+
override fun removeEldestEntry(eldest: Map.Entry<String, SoftReference<FoldCacheEntry>>): Boolean {
55+
return size > MAX_FOLD_CACHE_SIZE
56+
}
57+
}
5358

5459
fun <T> runInEdtAndGet(block: () -> T): T {
5560
val app = ApplicationManager.getApplication()

0 commit comments

Comments
 (0)