Polish "Add support for cache2k in memory caching"
See gh-28498
This commit is contained in:
@@ -850,6 +850,7 @@ Additional, cache-specific metrics are also available.
|
||||
|
||||
The following cache libraries are supported:
|
||||
|
||||
* Cache2k
|
||||
* Caffeine
|
||||
* EhCache 2
|
||||
* Hazelcast
|
||||
|
||||
@@ -44,6 +44,7 @@ If you have not defined a bean of type `CacheManager` or a `CacheResolver` named
|
||||
. <<io#io.caching.provider.couchbase,Couchbase>>
|
||||
. <<io#io.caching.provider.redis,Redis>>
|
||||
. <<io#io.caching.provider.caffeine,Caffeine>>
|
||||
. <<io#io.caching.provider.cache2k,Cache2k>>
|
||||
. <<io#io.caching.provider.simple,Simple>>
|
||||
|
||||
Additionally, {spring-boot-for-apache-geode}[Spring Boot for Apache Geode] provides {spring-boot-for-apache-geode-docs}#geode-caching-provider[auto-configuration for using Apache Geode as a cache provider].
|
||||
@@ -230,6 +231,19 @@ The auto-configuration ignores any other generic type.
|
||||
|
||||
|
||||
|
||||
[[io.caching.provider.cache2k]]
|
||||
==== Cache2k
|
||||
https://cache2k.org/[Cache2k] is an in-memory cache.
|
||||
If the Cache2k spring integration is present, a `SpringCache2kCacheManager` is auto-configured.
|
||||
|
||||
Caches can be created on startup by setting the configprop:spring.cache.cache-names[] property.
|
||||
Cache defaults can be customized using a `Cache2kBuilderCustomizer` bean.
|
||||
The following example shows a customizer that configures the capacity of the cache to 200 entries, with an expiration of 5 minutes:
|
||||
|
||||
include::code:MyCache2kDefaultsConfiguration[]
|
||||
|
||||
|
||||
|
||||
[[io.caching.provider.simple]]
|
||||
==== Simple
|
||||
If none of the other providers can be found, a simple implementation using a `ConcurrentHashMap` as the cache store is configured.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.io.caching.provider.cache2k;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.boot.autoconfigure.cache.Cache2kBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class MyCache2kDefaultsConfiguration {
|
||||
|
||||
@Bean
|
||||
public Cache2kBuilderCustomizer myCache2kDefaultsCustomizer() {
|
||||
// @formatter:off
|
||||
return (builder) -> builder.entryCapacity(200)
|
||||
.expireAfterWrite(5, TimeUnit.MINUTES);
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.springframework.boot.docs.io.caching.provider.cache2k
|
||||
|
||||
import org.springframework.boot.autoconfigure.cache.Cache2kBuilderCustomizer
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
class MyCache2kDefaultsConfiguration {
|
||||
|
||||
@Bean
|
||||
fun myCache2kDefaultsCustomizer(): Cache2kBuilderCustomizer {
|
||||
return Cache2kBuilderCustomizer { builder ->
|
||||
builder.entryCapacity(200)
|
||||
.expireAfterWrite(5, TimeUnit.MINUTES)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user