Skip to content

Commit

Permalink
Use a ConcurrentHashMap for CacheState#map
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou committed Feb 20, 2025
1 parent 3a16fab commit 2713aea
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 100 deletions.
15 changes: 12 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Versions.*
import BuildHelper.*
import com.typesafe.tools.mima.core.*
import zio.sbt.githubactions.Step

enablePlugins(ZioSbtEcosystemPlugin, ZioSbtCiPlugin)
Expand Down Expand Up @@ -123,25 +124,33 @@ lazy val docs = project

lazy val enforceMimaCompatibility = true // Enable / disable failing CI on binary incompatibilities

lazy val mimaFilters = Seq(
ProblemFilters.exclude[Problem]("zio.cache.ScopedCacheImplementation#CacheState.map"),
ProblemFilters.exclude[MissingClassProblem]("zio.cache.Platform*"),
ProblemFilters.exclude[Problem]("zio.cache.Cache#CacheState*"),
ProblemFilters.exclude[Problem]("zio.cache.ScopedCache#CacheState*"),
ProblemFilters.exclude[Problem]("zio.cache.ScopedCacheImplementation#CacheState*")
)

lazy val enableMimaSettingsJVM =
Def.settings(
mimaFailOnProblem := enforceMimaCompatibility,
mimaPreviousArtifacts := previousStableVersion.value.map(organization.value %% moduleName.value % _).toSet,
mimaBinaryIssueFilters ++= Seq()
mimaBinaryIssueFilters ++= mimaFilters
)

lazy val enableMimaSettingsJS =
Def.settings(
mimaFailOnProblem := enforceMimaCompatibility,
mimaPreviousArtifacts := previousStableVersion.value.map(organization.value %%% moduleName.value % _).toSet,
mimaBinaryIssueFilters ++= Seq()
mimaBinaryIssueFilters ++= mimaFilters
)

lazy val enableMimaSettingsNative =
Def.settings(
mimaFailOnProblem := enforceMimaCompatibility,
mimaPreviousArtifacts := previousStableVersion.value.map(organization.value %%% moduleName.value % _).toSet,
mimaBinaryIssueFilters ++= Seq()
mimaBinaryIssueFilters ++= mimaFilters
)

ThisBuild / ciCheckArtifactsBuildSteps +=
Expand Down
30 changes: 0 additions & 30 deletions zio-cache/js/src/main/scala/zio/cache/Platform.scala

This file was deleted.

31 changes: 0 additions & 31 deletions zio-cache/jvm/src/main/scala/zio/cache/Platform.scala

This file was deleted.

28 changes: 0 additions & 28 deletions zio-cache/native/src/main/scala/zio/cache/Platform.scala

This file was deleted.

6 changes: 3 additions & 3 deletions zio-cache/shared/src/main/scala/zio/cache/Cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import zio.internal.MutableConcurrentQueue
import zio.stacktracer.TracingImplicits.disableAutoTrace

import java.time.{Duration, Instant}
import java.util.Map
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.{AtomicBoolean, LongAdder}
import scala.annotation.tailrec

Expand Down Expand Up @@ -352,7 +352,7 @@ object Cache {
* The `CacheState` represents the mutable state underlying the cache.
*/
private final case class CacheState[Key, Error, Value](
map: Map[Key, MapValue[Key, Error, Value]],
map: ConcurrentHashMap[Key, MapValue[Key, Error, Value]],
keys: KeySet[Key],
accesses: MutableConcurrentQueue[MapKey[Key]],
hits: LongAdder,
Expand All @@ -367,7 +367,7 @@ object Cache {
*/
def initial[Key, Error, Value](): CacheState[Key, Error, Value] =
CacheState(
Platform.newConcurrentMap,
new ConcurrentHashMap(),
new KeySet,
MutableConcurrentQueue.unbounded,
new LongAdder,
Expand Down
5 changes: 3 additions & 2 deletions zio-cache/shared/src/main/scala/zio/cache/ScopedCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import zio.internal.MutableConcurrentQueue

import java.time.{Duration, Instant}
import java.util
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger, LongAdder}
import scala.jdk.CollectionConverters._

Expand Down Expand Up @@ -179,7 +180,7 @@ object ScopedCache {
* The `CacheState` represents the mutable state underlying the cache.
*/
private final case class CacheState[Key, Error, Value](
map: util.Map[Key, MapValue[Key, Error, Value]],
map: ConcurrentHashMap[Key, MapValue[Key, Error, Value]],
keys: KeySet[Key],
accesses: MutableConcurrentQueue[MapKey[Key]],
hits: LongAdder,
Expand All @@ -194,7 +195,7 @@ object ScopedCache {
*/
def initial[Key, Error, Value](): CacheState[Key, Error, Value] =
CacheState(
Platform.newConcurrentMap,
new ConcurrentHashMap(),
new KeySet,
MutableConcurrentQueue.unbounded,
new LongAdder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import zio.internal.MutableConcurrentQueue
import zio.{Clock, Exit, IO, Scope, UIO, Unsafe, ZEnvironment, ZIO}

import java.time.{Duration, Instant}
import java.util
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger, LongAdder}
import scala.jdk.CollectionConverters._

Expand Down Expand Up @@ -248,7 +248,7 @@ object ScopedCacheImplementation {
*/
def initial[Key, Error, Value](): CacheState[Key, Error, Value] =
CacheState(
Platform.newConcurrentMap,
new ConcurrentHashMap(),
new KeySet,
MutableConcurrentQueue.unbounded,
new LongAdder,
Expand Down Expand Up @@ -309,7 +309,7 @@ object ScopedCacheImplementation {
* The `CacheState` represents the mutable state underlying the cache.
*/
private final case class CacheState[Key, Error, Value](
map: util.Map[Key, MapValue[Key, Error, Value]],
map: ConcurrentHashMap[Key, MapValue[Key, Error, Value]],
keys: KeySet[Key],
accesses: MutableConcurrentQueue[MapKey[Key]],
hits: LongAdder,
Expand Down

0 comments on commit 2713aea

Please sign in to comment.