[ 
https://issues.apache.org/jira/browse/OAK-12148?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Rishabh Daim updated OAK-12148:
-------------------------------
    Description: 
Add package-private implementations and a public builder behind the Oak Cache 
API from TASK-1. No consumer module is changed — all existing call sites still 
compile.

  New classes in org.apache.jackrabbit.oak.cache:

  LirsCacheAdapter (package-private) — wraps CacheLIRS, implements 
OakCache/OakLoadingCache. Exception bridging: get(K, Function) wraps the 
Function into a Callable, delegates to CacheLIRS.get(K, Callable), catches
   ExecutionException and re-throws as CompletionException. get(K) on the 
loading cache similarly wraps. Adapts OakWeigher → Guava Weigher, 
OakRemovalListener/OakRemovalCause → CacheLIRS.EvictionCallback.

  CaffeineCacheAdapter (package-private) — wraps Caffeine Cache/LoadingCache, 
implements OakCache/OakLoadingCache. No exception adaptation needed — Caffeine 
already throws CompletionException. Adapts OakWeigher →
  Caffeine Weigher, OakRemovalListener/OakRemovalCause → Caffeine equivalents.

  OakCacheBuilder<K,V> (public) — fluent builder with two-level implementation 
resolution:
  1. Per-module override: .implementation(CacheImplementation) — pins this 
specific cache to one backend regardless of the global property. Use CAFFEINE 
to opt a module in ahead of the global flag; use LIRS to hold
   a module back after the global flag flips.
  2. Global default: system property oak.cache.type (lirs = default, caffeine).

  Per-module override beats global property.

  Supports: maximumWeight, maximumSize, weigher(OakWeigher), 
removalListener(OakRemovalListener), recordStats(), expireAfterAccess, 
expireAfterWrite, refreshAfterWrite, LIRS-specific params (segmentCount,
  stackMoveDistance, averageWeight). Methods: build() → OakCache, 
build(OakCacheLoader) → OakLoadingCache.

  OakCacheStatsAdapter (package-private) — extends AbstractCacheStats; 
getCurrentStats() converts OakCacheStats → Guava shim CacheStats (bridge until 
TASK-16 changes the base class return type).

  EmpiricalWeigher — modify to implement OakWeigher<CacheValue, CacheValue>.

  Add Caffeine as compile dependency in oak-core-spi/pom.xml (confined to the 
hidden adapter classes).

  Note on put(K, V, int memory): DefaultSegmentWriter in oak-segment-tar calls 
nodeCache.put(key, value, memoryCost). This CacheLIRS-specific 3-arg method is 
not on OakCache. Migration (TASK-12): replace with
  OakCache.put(key, value) and configure an OakWeigher on the builder that 
computes the same cost from key/value.

  Acceptance criteria:
  - All existing oak-core-spi tests pass
  - New OakCacheBuilderTest covers: LIRS build, Caffeine build, global toggle, 
per-module override (beats global), weigher/listener wiring, loading cache, 
stats adapter, exception shape (CompletionException on
  loader failure)
  - No consumer module is changed

  was:
Add package-private implementations and a public builder behind the Oak Cache 
API introduced in TASK-1. No consumer module is changed in this task — all 
existing call sites still compile.

  New classes in org.apache.jackrabbit.oak.cache (all package-private except 
OakCacheBuilder):

  LirsCacheAdapter — wraps CacheLIRS; implements OakLoadingCache. Exception 
bridging: get(K, Function) wraps the Function into a Callable, delegates to 
CacheLIRS.get(K, Callable), catches ExecutionException and
  re-throws as CompletionException; get(K) on loading cache similarly wraps. 
Adapts OakWeigher → Guava Weigher, OakRemovalListener/OakRemovalCause → 
CacheLIRS.EvictionCallback.

  CaffeineCacheAdapter — wraps Caffeine Cache/LoadingCache; implements 
OakLoadingCache. No exception adaptation needed — Caffeine already throws 
CompletionException. Adapts OakWeigher → Caffeine Weigher,
  OakRemovalListener/OakRemovalCause → Caffeine equivalents.

  OakCacheBuilder<K,V> — public fluent builder. Reads oak.cache.type system 
property (lirs = default during migration, caffeine). Supports: maximumWeight, 
maximumSize, weigher(OakWeigher),
  removalListener(OakRemovalListener), recordStats(), expireAfterAccess, 
expireAfterWrite, refreshAfterWrite, LIRS-specific params (segmentCount, 
stackMoveDistance, averageWeight). Methods: build() → OakCache,
  build(OakCacheLoader) → OakLoadingCache.

  OakCacheStatsAdapter — extends AbstractCacheStats; overrides 
getCurrentStats() converting OakCacheStats → Guava shim CacheStats (bridge 
until TASK-16 changes the base class return type).

  EmpiricalWeigher — modify to implement OakWeigher<CacheValue, CacheValue>.

  Add Caffeine as a compile dependency in oak-core-spi/pom.xml (confined to the 
hidden adapter classes).

  Acceptance criteria:
  - All existing oak-core-spi tests pass
  - New OakCacheBuilderTest covers: LIRS build, Caffeine build, toggle 
switching, weigher/listener wiring, loading cache, stats adapter, exception 
shape (CompletionException on loader failure)
  - No consumer module is changed


> Add hidden cache implementations and OakCacheBuilder in oak-core-spi
> --------------------------------------------------------------------
>
>                 Key: OAK-12148
>                 URL: https://issues.apache.org/jira/browse/OAK-12148
>             Project: Jackrabbit Oak
>          Issue Type: Sub-task
>            Reporter: Rishabh Daim
>            Assignee: Rishabh Daim
>            Priority: Major
>
> Add package-private implementations and a public builder behind the Oak Cache 
> API from TASK-1. No consumer module is changed — all existing call sites 
> still compile.
>   New classes in org.apache.jackrabbit.oak.cache:
>   LirsCacheAdapter (package-private) — wraps CacheLIRS, implements 
> OakCache/OakLoadingCache. Exception bridging: get(K, Function) wraps the 
> Function into a Callable, delegates to CacheLIRS.get(K, Callable), catches
>    ExecutionException and re-throws as CompletionException. get(K) on the 
> loading cache similarly wraps. Adapts OakWeigher → Guava Weigher, 
> OakRemovalListener/OakRemovalCause → CacheLIRS.EvictionCallback.
>   CaffeineCacheAdapter (package-private) — wraps Caffeine Cache/LoadingCache, 
> implements OakCache/OakLoadingCache. No exception adaptation needed — 
> Caffeine already throws CompletionException. Adapts OakWeigher →
>   Caffeine Weigher, OakRemovalListener/OakRemovalCause → Caffeine equivalents.
>   OakCacheBuilder<K,V> (public) — fluent builder with two-level 
> implementation resolution:
>   1. Per-module override: .implementation(CacheImplementation) — pins this 
> specific cache to one backend regardless of the global property. Use CAFFEINE 
> to opt a module in ahead of the global flag; use LIRS to hold
>    a module back after the global flag flips.
>   2. Global default: system property oak.cache.type (lirs = default, 
> caffeine).
>   Per-module override beats global property.
>   Supports: maximumWeight, maximumSize, weigher(OakWeigher), 
> removalListener(OakRemovalListener), recordStats(), expireAfterAccess, 
> expireAfterWrite, refreshAfterWrite, LIRS-specific params (segmentCount,
>   stackMoveDistance, averageWeight). Methods: build() → OakCache, 
> build(OakCacheLoader) → OakLoadingCache.
>   OakCacheStatsAdapter (package-private) — extends AbstractCacheStats; 
> getCurrentStats() converts OakCacheStats → Guava shim CacheStats (bridge 
> until TASK-16 changes the base class return type).
>   EmpiricalWeigher — modify to implement OakWeigher<CacheValue, CacheValue>.
>   Add Caffeine as compile dependency in oak-core-spi/pom.xml (confined to the 
> hidden adapter classes).
>   Note on put(K, V, int memory): DefaultSegmentWriter in oak-segment-tar 
> calls nodeCache.put(key, value, memoryCost). This CacheLIRS-specific 3-arg 
> method is not on OakCache. Migration (TASK-12): replace with
>   OakCache.put(key, value) and configure an OakWeigher on the builder that 
> computes the same cost from key/value.
>   Acceptance criteria:
>   - All existing oak-core-spi tests pass
>   - New OakCacheBuilderTest covers: LIRS build, Caffeine build, global 
> toggle, per-module override (beats global), weigher/listener wiring, loading 
> cache, stats adapter, exception shape (CompletionException on
>   loader failure)
>   - No consumer module is changed



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to