This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
LocalCache is a Java local caching library (io.meshware.cache) providing a unified abstraction over multiple caching backends — in-heap (Caffeine), off-heap (OHC), and Redis — with automatic cross-node cache synchronization via sync keys and Redis pub/sub. Targets Java 8+. Licensed under Apache 2.0.
# Full build (tests skipped by default via maven-surefire-plugin.skipTests=true)
mvn clean package
# Build with tests enabled
mvn clean package -Dmaven.surefire-plugin.skipTests=false
# Run a single test class
mvn test -pl cache-ihc -Dmaven.surefire-plugin.skipTests=false -Dtest=InHeapCacheTest
# Run a single test method
mvn test -pl cache-ihc -Dmaven.surefire-plugin.skipTests=false -Dtest=InHeapCacheTest#testPutAndGet
# Install locally
mvn clean install
# Skip tests explicitly
mvn clean install -DskipTestscache-api → Core interfaces (Cache, LocalCache, SynchronousCache, OffHeapCache, RedisCache)
cache-ihc → In-heap cache: Caffeine-based (AbstractCommonCache, AbstractLoadingCache, AbstractSynchronousCache)
cache-ohc → Off-heap cache: OHC-based (AbstractOffHeapCache, StringKeyOffHeapCache + Kryo/Protostuff serializers)
cache-spring → Spring integration: event-driven invalidation, CacheManager, AbstractCacheSyncManager
cache-redis → Redis backend: RedisClient, RedisAutoConfigure, pub/sub message publisher/subscriber
cache-samples → Demo Spring Boot application
Dependency flow: cache-api ← cache-ihc, cache-ohc ← cache-spring ← cache-redis. Samples depends on cache-redis.
Cache→LocalCache<K,V>→SynchronousCache<K,V,X,Y>(sync-key invalidation)Cache→LocalCache<K,V>→OffHeapCache<K,V>(off-heap with TTL + memory tracking)Cache→RedisCache(Redis operations + cross-node notify)
All cache implementations follow the template method pattern. Subclasses configure the cache by overriding:
initConfig()/init()— cache setupgetValueWhenExpired(key)— data loading on cache miss (LoadingCache variants)getValueWhenRefresh(key, oldValue)— data loading on TTL refresh (optional)initBuilder()/ serializer methods — OHC configuration
SynchronousCache entries have an associated "sync value" (version/timestamp). On read, the cache compares the current sync value against the stored one. If changed, the entry is invalidated and reloaded. Uses ReadWriteLock for thread safety. The sync values are stored in a separate DefaultSyncValueLocalCache (max 10000 entries, 8h TTL).
RedisClient.setWithNotify()sets a value and publishes aCacheDiscardEntity(cacheName + deleteKey) as JSON to a Redis channelRedisMessageSubscriberreceives the message, deserializes it, publishes a SpringCacheDiscardEvent- Cache beans with
@EventListeneronCacheDiscardEventcheck if the event targets their cache name and evict the key
RedisAutoConfigure (registered via META-INF/spring.factories) conditionally creates all Redis beans when cache.adapter.enable=true and cache.adapter.cache-type=redis.
Configuration properties (prefix cache.adapter):
enable(boolean, default true) — enable cache adaptercache-type(string) — backend type (currently "redis")discard-channel(string) — Redis pub/sub channel for invalidation messages
- Thread safety: AbstractCommonCache and AbstractLoadingCache use volatile + double-checked locking for lazy cache initialization
- Serialization: OHC module supports Kryo, Protostuff, String, Integer serializers under
cache-ohc/.../serializer/ - Version: Uses Maven CI-friendly
${revision}property (currently1.0.0-SNAPSHOT), flattened via flatten-maven-plugin - Test framework: JUnit 4 (primary), JUnit 5 (cache-ohc tests), Mockito (cache-spring tests). Note: cache-ohc test files are in the default package (no package declaration)