Skip to content

[core] Kyo-native Cache#1487

Open
fwbrasil wants to merge 4 commits intomainfrom
cache-core
Open

[core] Kyo-native Cache#1487
fwbrasil wants to merge 4 commits intomainfrom
cache-core

Conversation

@fwbrasil
Copy link
Collaborator

We currently depend on Caffeine in kyo-cache, which can't be reused in JS and Native. This PR introduces a new Cache primitive in kyo-core with the safe and unsafe APIs pattern. Please see scaladocs for more information on the design.

@fwbrasil fwbrasil force-pushed the cache-core branch 2 times, most recently from 3255745 to f41aa29 Compare March 12, 2026 03:57
opaque type Slot[+V] = V | AnyRef | Null

object Slot:
val empty: Slot[Nothing] = null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this isn't a new AnyRef?

* @return
* A memoized version of the function
*/
def memo[A](
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can think of use cases that would require multiple functions, but may produce the same value. Do you think we could support that?

if promise.unsafe.interrupt() then
store.remove(v)
} {
Abort.run[Throwable](f(v)).map {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to run Abort[Any] to support any type of failure?

Suggested change
Abort.run[Throwable](f(v)).map {
Abort.runWith[Throwable](f(v)) {

promise.unsafe.completeDiscard(Result.Success(v))
v
}
case r: Result.Error[Nothing] @unchecked =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be?

Suggested change
case r: Result.Error[Nothing] @unchecked =>
case r: Result.Error[Throwable] @unchecked =>

val s = values.get(slot)
if s.isLocked then
// Slot being written — restart
add(key, value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will re-acquire the hashcode of the key. Should that be avoidable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants