Skip to content

OAK-12147 : introduce Oak cache API interfaces#2814

Merged
rishabhdaim merged 3 commits intotrunkfrom
OAK-12147
Mar 26, 2026
Merged

OAK-12147 : introduce Oak cache API interfaces#2814
rishabhdaim merged 3 commits intotrunkfrom
OAK-12147

Conversation

@rishabhdaim
Copy link
Contributor

Summary

Introduces the Oak-owned cache API in oak-core-spi (org.apache.jackrabbit.oak.cache), decoupling callers from CacheLIRS and Guava implementation details. This is TASK-1 of the Caffeine migration (OAK-11300).

Changes

  • OakCache<K,V> — size-bounded thread-safe cache interface (@ProviderType)
  • OakLoadingCache<K,V> — extends OakCache, adds auto-loading get(K) and refresh(K) (@ProviderType)
  • OakCacheLoader<K,V>@FunctionalInterface loader supplied to OakCacheBuilder.build()
  • OakWeigher<K,V>@FunctionalInterface weigher for weight-based eviction
  • OakRemovalListener<K,V>@FunctionalInterface eviction/invalidation callback
  • OakRemovalCause — enum (EXPLICIT, REPLACED, SIZE, EXPIRED, COLLECTED)
  • OakCacheStats — immutable value object with hit/miss/load/eviction counters and minus() delta support
  • package-info.java — bumped @Version from 2.0 to 2.1 (OSGi minor bump for new public types)
  • OakCacheStatsTest — 9 JUnit 4 tests covering all methods and edge cases

No production call sites are changed in this task. OakCacheBuilder (TASK-2) will wire these interfaces to CacheLIRS and Caffeine adapters.

Test Plan

  • OakCacheStatsTest — 9 tests, all passing
  • mvn test -pl oak-core-spi — BUILD SUCCESS

Links

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
73.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link
Contributor

@reschke reschke left a comment

Choose a reason for hiding this comment

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

LGTM. If there's something wrong we'll find out later.

* A size-bounded, thread-safe cache.
*
* <p>Implementations may use different eviction strategies (LIRS, W-TinyLFU/Caffeine,
* etc.) but callers see only this interface. Obtain instances via OakCacheBuilder.</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* etc.) but callers see only this interface. Obtain instances via OakCacheBuilder.</p>
* etc.) but callers see only this interface. Obtain instances via OakCacheBuilder.

@rishabhdaim rishabhdaim merged commit 017a3fd into trunk Mar 26, 2026
2 of 3 checks passed
@rishabhdaim rishabhdaim deleted the OAK-12147 branch March 26, 2026 12:28
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