mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
drop inmemory caches for unsaved documents on low memory (IDEA-153382)
This commit is contained in:
@@ -148,7 +148,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe
|
||||
extension instanceof StringStubIndexExtension && ((StringStubIndexExtension)extension).traceKeyHashToVirtualFileMapping()
|
||||
);
|
||||
|
||||
final MemoryIndexStorage<K, StubIdList> memStorage = new MemoryIndexStorage<K, StubIdList>(storage);
|
||||
final MemoryIndexStorage<K, StubIdList> memStorage = new MemoryIndexStorage<K, StubIdList>(storage, indexKey);
|
||||
MyIndex<K> index = new MyIndex<>(new IndexExtension<K, StubIdList, Void>() {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -388,7 +388,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
}
|
||||
|
||||
state.registerIndex(name,
|
||||
createIndex(extension, new MemoryIndexStorage<K, V>(storage)),
|
||||
createIndex(extension, new MemoryIndexStorage<K, V>(storage, name)),
|
||||
new FileBasedIndex.InputFilter() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,6 +76,14 @@ public class MapReduceIndex<Key, Value, Input> implements UpdatableIndex<Key,Val
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (myStorage instanceof MemoryIndexStorage) {
|
||||
getWriteLock().lock();
|
||||
try {
|
||||
((MemoryIndexStorage<Key, Value>)myStorage).clearCaches();
|
||||
} finally {
|
||||
getWriteLock().unlock();
|
||||
}
|
||||
}
|
||||
flush();
|
||||
} catch (StorageException e) {
|
||||
LOG.info(e);
|
||||
|
||||
@@ -36,6 +36,7 @@ public class MemoryIndexStorage<Key, Value> implements IndexStorage<Key, Value>
|
||||
@NotNull
|
||||
private final IndexStorage<Key, Value> myBackendStorage;
|
||||
private final List<BufferingStateListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final ID<?, ?> myIndexId;
|
||||
private boolean myBufferingEnabled;
|
||||
|
||||
public interface BufferingStateListener {
|
||||
@@ -45,7 +46,12 @@ public class MemoryIndexStorage<Key, Value> implements IndexStorage<Key, Value>
|
||||
}
|
||||
|
||||
public MemoryIndexStorage(@NotNull IndexStorage<Key, Value> backend) {
|
||||
this(backend, null);
|
||||
}
|
||||
|
||||
public MemoryIndexStorage(@NotNull IndexStorage<Key, Value> backend, ID<?, ?> indexId) {
|
||||
myBackendStorage = backend;
|
||||
myIndexId = indexId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -85,6 +91,16 @@ public class MemoryIndexStorage<Key, Value> implements IndexStorage<Key, Value>
|
||||
}
|
||||
}
|
||||
|
||||
void clearCaches() {
|
||||
if (myMap.size() == 0) return;
|
||||
String message = "Dropping caches for " + (myIndexId != null ? myIndexId:this) + ", number of items:" + myMap.size();
|
||||
FileBasedIndexImpl.LOG.info(message);
|
||||
|
||||
for(ChangeTrackingValueContainer<Value> v:myMap.values()) {
|
||||
v.dropMergedData();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws StorageException {
|
||||
myBackendStorage.close();
|
||||
|
||||
Reference in New Issue
Block a user