void () { RecursionManager.disableMissedCacheAssertions(getTestRootDisposable()); final PsiClass clazz = myFixture.addClass("class Foo {}"); assert clazz.equals(myFixture.findClass("Foo")); DumbModeTestUtils.runInDumbModeSynchronously(getProject(), () -> { final AtomicInteger indexQueries = new AtomicInteger(0); final AtomicInteger plainQueries = new AtomicInteger(0); final CachedValue<PsiClass> stubQuery = CachedValuesManager.getManager(getProject()).createCachedValue(() -> { indexQueries.incrementAndGet(); return CachedValueProvider.Result.create(myFixture.findClass("Foo"), PsiModificationTracker.MODIFICATION_COUNT); }); final CachedValue<Boolean> idQuery = CachedValuesManager.getManager(getProject()).createCachedValue(() -> { indexQueries.incrementAndGet(); GlobalSearchScope fileScope = GlobalSearchScope.fileScope(clazz.getContainingFile()); IdIndexEntry key = new IdIndexEntry("Foo", true); boolean hasId = !FileBasedIndex.getInstance().getContainingFiles(IdIndex.NAME, key, fileScope).isEmpty(); return CachedValueProvider.Result.create(hasId, PsiModificationTracker.MODIFICATION_COUNT); }); final CachedValue<String> plainValue = CachedValuesManager.getManager(getProject()).createCachedValue(() -> { plainQueries.incrementAndGet(); return CachedValueProvider.Result.create("x", PsiModificationTracker.MODIFICATION_COUNT); }); // index queries aren't cached for (int i = 0; i < 5; i++) { assert clazz.equals(FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RELIABLE_DATA_ONLY, asComputable(stubQuery))); } assert indexQueries.get() >= 5; indexQueries.set(0); assert FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RAW_INDEX_DATA_ACCEPTABLE, asComputable(idQuery)); assert FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RELIABLE_DATA_ONLY, asComputable(idQuery)); assert indexQueries.get() >= 2; // non-index queries should work as usual for (int i = 0; i < 3; i++) { assert "x".equals( FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RAW_INDEX_DATA_ACCEPTABLE, asComputable(plainValue))); assert "x".equals(FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RELIABLE_DATA_ONLY, asComputable(plainValue))); } assert plainQueries.get() > 0 && plainQueries.get() < 3 * 2; // cache queries inside single ignoreDumbMode indexQueries.set(0); getPsiManager().dropPsiCaches(); FileBasedIndex.getInstance() .ignoreDumbMode(DumbModeAccessType.RAW_INDEX_DATA_ACCEPTABLE, () -> { for (int i = 0; i < 5; i++) { assert idQuery.getValue(); } assert indexQueries.get() > 0 && indexQueries.get() < 5; }); indexQueries.set(0); getPsiManager().dropPsiCaches(); FileBasedIndex.getInstance() .ignoreDumbMode(DumbModeAccessType.RELIABLE_DATA_ONLY, () -> { for (int i = 0; i < 5; i++) { assert clazz.equals(stubQuery.getValue()); } assert indexQueries.get() > 0 && indexQueries.get() < 5; }); }); }