Skip to content

Instantly share code, notes, and snippets.

@jelinski
Created November 26, 2019 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jelinski/4b8c0e280f4aa74a7dcfea03f7115e9b to your computer and use it in GitHub Desktop.
Save jelinski/4b8c0e280f4aa74a7dcfea03f7115e9b to your computer and use it in GitHub Desktop.
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static java.time.Duration.ofHours;
import static java.time.Duration.ofMinutes;
@Configuration
public class CacheConfiguration {
@Bean
public CaffeineCache firstCaffeineCache() {
return new CaffeineCache("firstCache",
Caffeine.newBuilder()
.weakKeys()
.initialCapacity(100)
.maximumSize(512)
.expireAfterWrite(ofHours(12))
.build());
}
@Bean
public CaffeineCache secondCaffeineCache() {
return new CaffeineCache("secondCache",
Caffeine.newBuilder()
.maximumSize(128)
.expireAfterAccess(ofMinutes(30))
.build());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment