in entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/EntityIterableBase.java [517:546]
public final CachedInstanceIterable getOrCreateCachedInstance(@NotNull PersistentStoreTransaction txn, boolean forceCount) {
if (store == null) {
throw new NullPointerException("Can't create cached instance for EMPTY iterable");
}
final EntityIterableCache cache = store.getEntityIterableCache();
final boolean canBeCached = !cache.getCachingDisabled() && canBeCached();
CachedInstanceIterable cached = null;
if (canBeCached) {
cached = txn.getCachedInstance(this);
}
if (cached == null || cached.getHandle().isExpired()) {
cached = createCachedInstance(txn);
if (canBeReordered() && !store.getConfig().isReorderingDisabled() && !cached.isSortedById()) {
cached = cached.orderById();
}
if (canBeCached) {
// if this iterable may be inconsistent and the transaction is read-only
// then revert it in order to hold the latest cache adapter instance
if (!getHandle().isConsistent() && txn.isReadonly()) {
txn.revertCaches();
}
txn.addCachedInstance(cached);
} else {
cache.setCachedCount(getHandle(), cached.size());
}
} else if (forceCount) {
cache.setCachedCount(getHandle(), cached.size());
}
return cached;
}