[CLI] free cached values
^ KTIJ-24447
This commit is contained in:
+5
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.impl.base
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.roots.ProjectRootModificationTracker
|
import com.intellij.openapi.roots.ProjectRootModificationTracker
|
||||||
|
import com.intellij.openapi.util.LowMemoryWatcher
|
||||||
import com.intellij.psi.util.PsiModificationTracker
|
import com.intellij.psi.util.PsiModificationTracker
|
||||||
import org.jetbrains.annotations.TestOnly
|
import org.jetbrains.annotations.TestOnly
|
||||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
|
import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
|
||||||
@@ -61,6 +62,10 @@ private class KtAnalysisSessionCache(project: Project) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
init {
|
||||||
|
LowMemoryWatcher.register({ cache.clearCachedValues() }, project)
|
||||||
|
}
|
||||||
|
|
||||||
@TestOnly
|
@TestOnly
|
||||||
fun clear() {
|
fun clear() {
|
||||||
cache.clear()
|
cache.clear()
|
||||||
|
|||||||
+11
@@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.psi.util.CachedValue
|
import com.intellij.psi.util.CachedValue
|
||||||
import com.intellij.psi.util.CachedValueProvider
|
import com.intellij.psi.util.CachedValueProvider
|
||||||
import com.intellij.psi.util.CachedValuesManager
|
import com.intellij.psi.util.CachedValuesManager
|
||||||
|
import com.intellij.util.CachedValueBase
|
||||||
import com.intellij.util.containers.ContainerUtil
|
import com.intellij.util.containers.ContainerUtil
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
@@ -17,6 +18,8 @@ public abstract class SoftCachedMap<K : Any, V : Any> {
|
|||||||
|
|
||||||
public abstract fun clear()
|
public abstract fun clear()
|
||||||
|
|
||||||
|
public abstract fun clearCachedValues()
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
public fun <K : Any, V : Any> create(
|
public fun <K : Any, V : Any> create(
|
||||||
project: Project,
|
project: Project,
|
||||||
@@ -48,6 +51,12 @@ private class SoftCachedMapWithTrackers<K : Any, V : Any>(
|
|||||||
cache.clear()
|
cache.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun clearCachedValues() {
|
||||||
|
cache.values.forEach {
|
||||||
|
(it as? CachedValueBase<*>)?.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getOrPut(key: K, create: () -> V): V {
|
override fun getOrPut(key: K, create: () -> V): V {
|
||||||
return cache.getOrPut(key) {
|
return cache.getOrPut(key) {
|
||||||
CachedValuesManager.getManager(project).createCachedValue {
|
CachedValuesManager.getManager(project).createCachedValue {
|
||||||
@@ -67,6 +76,8 @@ private class SoftCachedMapWithoutTrackers<K : Any, V : Any>(kind: Kind) : SoftC
|
|||||||
cache.clear()
|
cache.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun clearCachedValues() {}
|
||||||
|
|
||||||
override fun getOrPut(key: K, create: () -> V): V {
|
override fun getOrPut(key: K, create: () -> V): V {
|
||||||
return cache.getOrPut(key, create)
|
return cache.getOrPut(key, create)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user