Skip to content

Commit

Permalink
Revert "JT-78303: Use local cache for mutable adapter"
Browse files Browse the repository at this point in the history
This reverts commit 5a0904e.
  • Loading branch information
vladimir-zatsepin committed Jan 30, 2024
1 parent 4e386b1 commit 4d80c88
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal open class EntityIterableCacheAdapter(
cache.remove(key)
}

open fun count() = cache.count()
fun count() = cache.count()

fun size() = cache.size()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,17 @@ internal class EntityIterableCacheAdapterMutable private constructor(
}
}

private val entitiesToCache = HashMap<EntityIterableHandle, CachedInstanceIterable>()
private val entitiesToRemove = HashSet<EntityIterableHandle>()

override fun getObject(key: EntityIterableHandle): CachedInstanceIterable? {
if (entitiesToRemove.contains(key)) {
return null
}
return entitiesToCache[key] ?: super.getObject(key)
}

override fun getUpdatable(key: EntityIterableHandle): Updatable? {
return entitiesToCache[key] as Updatable? ?: super.getUpdatable(key)
fun endWrite(): EntityIterableCacheAdapter {
return EntityIterableCacheAdapter(config, cache, stickyObjects)
}

override fun cacheObject(key: EntityIterableHandle, value: CachedInstanceIterable) {
entitiesToCache[key] = value
override fun cacheObject(key: EntityIterableHandle, it: CachedInstanceIterable) {
super.cacheObject(key, it)
handleDistribution.addHandle(key)
}

override fun count(): Long {
return super.count() + entitiesToCache.size - entitiesToRemove.size
}

fun cacheObjectNotAffectingHandleDistribution(key: EntityIterableHandle, value: CachedInstanceIterable) {
entitiesToCache[key] = value
}

override fun remove(key: EntityIterableHandle) {
entitiesToRemove.add(key)
handleDistribution.removeHandle(key)
}

override fun clear() {
entitiesToCache.clear()
entitiesToRemove.clear()
handleDistribution.clear()
}

fun endWrite(): EntityIterableCacheAdapter {
entitiesToCache.forEach { (handle, value) -> cache.put(handle, value) }
entitiesToRemove.forEach { cache.remove(it) }
return EntityIterableCacheAdapter(config, cache, stickyObjects)
fun cacheObjectNotAffectingHandleDistribution(handle: EntityIterableHandle, it: CachedInstanceIterable) {
super.cacheObject(handle, it)
}

fun update(checker: HandleCheckerAdapter) {
Expand Down Expand Up @@ -129,6 +98,17 @@ internal class EntityIterableCacheAdapterMutable private constructor(
stickyObjects[handle] = updatable
}

override fun remove(key: EntityIterableHandle) {
check(!key.isSticky) { "Cannot remove sticky object" }
super.remove(key)
handleDistribution.removeHandle(key)
}

override fun clear() {
super.clear()
handleDistribution.clear()
}

private class HandleDistribution(cacheCount: Int) {

val removed: MutableSet<EntityIterableHandle>
Expand Down

0 comments on commit 4d80c88

Please sign in to comment.