Rishabh Daim created OAK-12148:
----------------------------------

             Summary: 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


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



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

Reply via email to