Skip to content

Commit

Permalink
Update with changes on master (#90)
Browse files Browse the repository at this point in the history
* Implement Cache#invalidateAll (#51)

* implement Cache#invalidateAll

* format

* Added size to `CacheStats`. (#53)

* Added size and capacity to `CacheStats`.

* Removed `capacity` from stats.

* Update Node.js to v14.18.0 (#55)

Co-authored-by: Renovate Bot <[email protected]>

* Add `refresh` method to trigger a lookup call. (#52)

* First attempt to resolve #42

* Fixed a concurrency issue

* Refactoring

* Minor refactorings, scalafmt & sbt upgrades

* Fixing build

* Refactoring: replaced vars with ref

* Reformatted build.sbt to fix build.

* Fixing build

* Fixing build

* Updated docs

* Fixed formatting and addressed PR comments.

* Fixed docs

* Added a unit test for `refresh` method.

* Improved docs

* Minor improvement

* Bumped scalafmt

* Bumped scalajs

* Update Node.js to v14.18.1 (#58)

Co-authored-by: Renovate Bot <[email protected]>

* Update actions/checkout action to v2.3.5 (#59)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16 (#61)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16.13.0 (#62)

Co-authored-by: Renovate Bot <[email protected]>

* Update actions/checkout action to v2.4.0 (#64)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16.13.1 (#65)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16.13.2 (#68)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16.14.0 (#70)

Co-authored-by: Renovate Bot <[email protected]>

* Update actions/checkout action (#72)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16.14.1 (#73)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16.14.2 (#74)

Co-authored-by: Renovate Bot <[email protected]>

* Update hmarr/auto-approve-action action to v2.2.0 (#77)

Co-authored-by: Renovate Bot <[email protected]>

* Update actions/checkout action to v3.0.1 (#82)

Co-authored-by: Renovate Bot <[email protected]>

* Update actions/checkout action to v3.0.2 (#83)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16.15.0 (#84)

Co-authored-by: Renovate Bot <[email protected]>

* Update Node.js to v16.15.1 (#87)

Co-authored-by: Renovate Bot <[email protected]>

* Cache managed resource (#71)

* Add .bsp to .gitignore

* Extract KeySet and MapKey out of Cache

Because they probably going to be shared with ManagedCache

* define interface for a ManagedCache

* Copy/Paste: cache implementation and cache test for managedCache

* Adapt cache implementation and test for ManagedCache

* make ManagedCache.get return Managed[Error, Value] instead of UIO[Managed[Error, Value]]

* Make ManagedCache work on 2.11 and Scala 3

* Fix doc after Adam's review

* fixup! Fix doc after Adam's review

* fixup! Fix doc after Adam's review

* fix managed cache invalidate not being lazy (#88)

* run finalizer after acquire fails

* fix compilation issue

* format

Co-authored-by: Adam Fraser <[email protected]>
Co-authored-by: Terry L <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: LUC DUZAN <[email protected]>
  • Loading branch information
6 people authored Jun 25, 2022
1 parent df6687f commit 9f507ad
Show file tree
Hide file tree
Showing 13 changed files with 1,590 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
auto-approve:
runs-on: ubuntu-20.04
steps:
- uses: hmarr/auto-approve-action@v2.1.0
- uses: hmarr/auto-approve-action@v2.2.0
if: github.actor == 'scala-steward' || github.actor == 'renovate[bot]'
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
timeout-minutes: 30
steps:
- name: Checkout current branch
uses: actions/[email protected].0
uses: actions/[email protected].2
with:
fetch-depth: 0
- name: Setup Scala and Java
Expand All @@ -33,7 +33,7 @@ jobs:
timeout-minutes: 60
steps:
- name: Checkout current branch
uses: actions/[email protected].0
uses: actions/[email protected].2
- name: Setup Scala and Java
uses: olafurpg/setup-scala@v13
- name: Cache scala dependencies
Expand All @@ -52,7 +52,7 @@ jobs:
platform: ['JVM', 'JS', 'Native']
steps:
- name: Checkout current branch
uses: actions/[email protected].0
uses: actions/[email protected].2
with:
fetch-depth: 0
- name: Setup Scala and Java
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
if: github.event_name != 'pull_request'
steps:
- name: Checkout current branch
uses: actions/[email protected].0
uses: actions/[email protected].2
with:
fetch-depth: 0
- name: Setup Scala and Java
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,12 @@ project/plugins/project/
.metals/
metals.sbt
.bloop/
.bsp/
project/secret

# mdoc
website/node_modules
website/build
website/i18n/en.json
website/static/api

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.14.2
16.15.1
7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ lazy val zioCache = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.settings(buildInfoSettings("zio.cache"))
.settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test
"dev.zio" %% "zio" % zioVersion,
"org.scala-lang.modules" %% "scala-collection-compat" % "2.7.0",
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test
)
)
.settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"))
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.8")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.9")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.3")
Expand All @@ -12,7 +12,7 @@ addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject"
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.21")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
addSbtPlugin("pl.project13.scala" % "sbt-jcstress" % "0.2.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")

Expand Down
67 changes: 0 additions & 67 deletions zio-cache/shared/src/main/scala/zio/cache/Cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,6 @@ object Cache {
}
}

/**
* A `MapKey` represents a key in the cache. It contains mutable references
* to the previous key and next key in the `KeySet` to support an efficient
* implementation of a sorted set of keys.
*/
private final class MapKey[Key](
val value: Key,
var previous: MapKey[Key] = null,
var next: MapKey[Key] = null
)

/**
* A `MapValue` represents a value in the cache. A value may either be
* `Pending` with a `Promise` that will contain the result of computing the
Expand Down Expand Up @@ -343,60 +332,4 @@ object Cache {
new AtomicBoolean(false)
)
}

/**
* A `KeySet` is a sorted set of keys in the cache ordered by last access.
* For efficiency, the set is implemented in terms of a doubly linked list
* and is not safe for concurrent access.
*/
private final class KeySet[Key] {
private[this] var head: MapKey[Key] = null
private[this] var tail: MapKey[Key] = null

/**
* Adds the specified key to the set.
*/
def add(key: MapKey[Key]): Unit =
if (key ne tail) {
if (tail ne null) {
val previous = key.previous
val next = key.next
if (next ne null) {
key.next = null
if (previous ne null) {
previous.next = next
next.previous = previous
} else {
head = next
head.previous = null
}
}
tail.next = key
key.previous = tail
tail = key
} else {
head = key
tail = key
}
}

/**
* Removes the lowest priority key from the set.
*/
def remove(): MapKey[Key] = {
val key = head
if (key ne null) {
val next = key.next
if (next ne null) {
key.next = null
head = next
head.previous = null
} else {
head = null
tail = null
}
}
key
}
}
}
57 changes: 57 additions & 0 deletions zio-cache/shared/src/main/scala/zio/cache/KeySet.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package zio.cache

/**
* A `KeySet` is a sorted set of keys in the cache ordered by last access.
* For efficiency, the set is implemented in terms of a doubly linked list
* and is not safe for concurrent access.
*/
private[cache] final class KeySet[Key] {
private[this] var head: MapKey[Key] = null
private[this] var tail: MapKey[Key] = null

/**
* Adds the specified key to the set.
*/
def add(key: MapKey[Key]): Unit =
if (key ne tail) {
if (tail ne null) {
val previous = key.previous
val next = key.next
if (next ne null) {
key.next = null
if (previous ne null) {
previous.next = next
next.previous = previous
} else {
head = next
head.previous = null
}
}
tail.next = key
key.previous = tail
tail = key
} else {
head = key
tail = key
}
}

/**
* Removes the lowest priority key from the set.
*/
def remove(): MapKey[Key] = {
val key = head
if (key ne null) {
val next = key.next
if (next ne null) {
key.next = null
head = next
head.previous = null
} else {
head = null
tail = null
}
}
key
}
}
12 changes: 12 additions & 0 deletions zio-cache/shared/src/main/scala/zio/cache/MapKey.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package zio.cache

/**
* A `MapKey` represents a key in the cache. It contains mutable references
* to the previous key and next key in the `KeySet` to support an efficient
* implementation of a sorted set of keys.
*/
private[cache] final class MapKey[Key](
val value: Key,
var previous: MapKey[Key] = null,
var next: MapKey[Key] = null
)
Loading

0 comments on commit 9f507ad

Please sign in to comment.