Fork me on GitHub

cache2k 1.4.0.Final - Andeman Sea

cache2k is a high performance and light weight in-process caching library. Compared to other libraries (EHCache, Guava and Caffeine) it achieves the highest throughput for cache hits while still providing one of the best eviction efficiency. Advanced features of cache2k, like refresh ahead and resilience can solve typical application problems with ease.

This change log lists the complete changes since the last stable version 1.2.4.Final.

New and Noteworthy

  • Weigher
  • AsyncCacheLoader
  • Eviction listener and eviction improvements
  • Synchronous execution of expiry listener
  • Micrometer support
  • Online resize of caches
  • Support for GraalVM native image build

API Changes

New methods / fields:

  • CacheManager.STANDARD_DEFAULT_MANAGER_NAME
  • CacheInfoMXBean.isWeigherPresent()
  • CacheInfoMXBean.isLoaderPresent()
  • CacheInfoMXBean.getTotalWeight()
  • CacheInfoMXBean.getMaximumWeight()
  • CacheInfoMXBean.getCapacityLimit()
  • Cache.getStatistics()

New interface:

  • AsyncCacheLoader

Deprecation:

  • IntCache, LongCache
  • Cache2kBuilder.buildIntCache(), Cache2kBuilder.buildLongCache()

API Changes and Potential breakages

Cache2kBuilder.addListener will execute an EntryExpiredLister synchronously. In version 1.2 an expiry listener was always executed asynchronously. This is an potentially incompatible change, in case expiry listeners are used. Review the existing client code and make sure that addAsyncListeners is used for an EntryExpiredLister if that is wanted.

Fixes

  • Fix CacheManager.setDefaultName, see GH#108
  • race of refresh and delete: if an entry is deleted via Cache.remove it was not reappearing when refreshed concurrently
  • fix missing expiry listener call after a created listener call, in case expiry during the insert
  • expiry, expireAfterWrite, refreshAhead: Fix race condition of a Cache.put and the

Improvements

  • Remove randomized hash seed and simplify the “rehashing” of hash codes identical to Java HashMap and ConcurrentHashMap
  • Async Cacheloader GH#93
  • CacheEntryEvictionListener added, GH#59
  • Expose cache statistics via Cache.getStatistics()
  • Eviction: Efficiency improvements, see comment: https://github.com/cache2k/cache2k/issues/101#issuecomment-523003823
  • Expiry listener supports synchronous operation
  • Deprecated IntCache and LongCache
  • Internal: Improvement and simplification of ExceptionPropagator handling termination of the probation period after a refresh.
  • Cache.invoke / EntryProcessor: Internal improvements when using listeners: avoid unnecessary entry reads
  • internal cleanup: use common code for refresh in different cache variants
  • eviction efficiency fix for a few special short traces
  • Support for new cache methods from Spring Framework 5.2
  • doc clarifications and improvements
  • SpringCache2kCacheManager.setAllowUnknownCache is true by default, to minimize initial setup
  • CacheEntry.toString output does not call toString on the value and print hashCode instead
  • doc clarifications
  • Code style improvements

Using this cache2k version

The binaries are available on maven central.

For Java SE/EE and Android environments

For Maven users:

    <dependency>
      <groupId>org.cache2k</groupId>
      <artifactId>cache2k-base-pom</artifactId>
      <version>1.4.0.Final</version>
      <type>pom</type>
    </dependency>

Recommended for Gradle users:

def cache2kVersion = '1.4.0.Final'

dependencies {
    implementation "org.cache2k:cache2k-api:${cache2kVersion}"
    runtimeOnly "org.cache2k:cache2k-core:${cache2kVersion}"
}

Note to Android users: The included jar files contain code that might only be needed in server environments (e.g. JMX support). It is possible to strip unnecessary code. Example ProGuard rules can be found at Andriod - cache2k User Guide

Using the JCache / JSR107 provider

Maven users include the cache2k JCache provider this way:

    <dependency>
      <groupId>org.cache2k</groupId>
      <artifactId>cache2k-jcache</artifactId>
      <version>1.4.0.Final</version>
      <scope>runtime</scope>
    </dependency>

For Gradle users:

dependencies {
    runtimeOnly "org.cache2k:cache2k-jcache:1.4.0.Final"
}

Implementation details, tuning tips and hints on configuration can be found at: JCache - cache2k User Guide