All Projects → stepio → coffee-boots

stepio / coffee-boots

Licence: Apache-2.0 license
Support property-based configuring of multiple Caffeine caches for Spring Cache abstraction.

Projects that are alternatives of or similar to coffee-boots

Javasrc
Ian's Collected code examples from the O'Reilly Java Cookbook & elsewhere
Stars: ✭ 165 (+650%)
Mutual labels:  environment
Environ Config
Python Application Configuration With Environment Variables
Stars: ✭ 210 (+854.55%)
Mutual labels:  environment
adopt-a-drain
A web application that allows citizens to "adopt" a storm drain in San Francisco. In use, and in development at other brigades. Looking for a maintainer or someone interested in developing further in collaboration with others across the country.
Stars: ✭ 43 (+95.45%)
Mutual labels:  environment
Env Ci
Get environment variables exposed by CI services
Stars: ✭ 180 (+718.18%)
Mutual labels:  environment
Env Var
Verification, sanitization, and type coercion for environment variables in Node.js
Stars: ✭ 201 (+813.64%)
Mutual labels:  environment
Setup Miniconda
Set up your GitHub Actions workflow with conda via miniconda
Stars: ✭ 222 (+909.09%)
Mutual labels:  environment
Envy
Envy automatically exposes environment variables for all of your Go flags
Stars: ✭ 150 (+581.82%)
Mutual labels:  environment
ai-learning-environments
List of environments and competitions for RL and AI training
Stars: ✭ 14 (-36.36%)
Mutual labels:  environment
Terraform Aws Elastic Beanstalk Environment
Terraform module to provision an AWS Elastic Beanstalk Environment
Stars: ✭ 211 (+859.09%)
Mutual labels:  environment
Config
12 factor configuration as a typesafe struct in as little as two function calls
Stars: ✭ 251 (+1040.91%)
Mutual labels:  environment
Gym Sokoban
Sokoban environment for OpenAI Gym
Stars: ✭ 186 (+745.45%)
Mutual labels:  environment
Emacs Direnv
direnv integration for emacs
Stars: ✭ 194 (+781.82%)
Mutual labels:  environment
Ma Gym
A collection of multi agent environments based on OpenAI gym.
Stars: ✭ 226 (+927.27%)
Mutual labels:  environment
Datasets For Good
List of datasets to apply stats/machine learning/technology to the world of social good.
Stars: ✭ 174 (+690.91%)
Mutual labels:  environment
bandmaster
Simple and easily extendable Go library for managing runtime services & dependencies (datastores, APIs, MQs, custom...).
Stars: ✭ 43 (+95.45%)
Mutual labels:  environment
Sustainable Earth
A curated list of all things sustainable
Stars: ✭ 159 (+622.73%)
Mutual labels:  environment
Rails Env Favicon
Gem to display the rails environment on the favicon
Stars: ✭ 212 (+863.64%)
Mutual labels:  environment
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (+227.27%)
Mutual labels:  environment
dotenvy
Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents
Stars: ✭ 31 (+40.91%)
Mutual labels:  environment
Loft
Namespace & Virtual Cluster Manager for Kubernetes - Lightweight Virtual Clusters, Self-Service Provisioning for Engineers and 70% Cost Savings with Sleep Mode
Stars: ✭ 239 (+986.36%)
Mutual labels:  environment

Coffee Boots

Build Status Sonarcloud Status Codacy Badge DepShield Badge Maven Central Javadocs Apache 2.0 License

Coffee Boots project implements (property-based) configuring of multiple Caffeine caches for Spring Cache abstraction. It works best with Spring Boot, implementing auto-configuration mechanism. This means that in most cases you don't have to create any beans yourself, just add dependency to the latest version:

<dependency>
    <groupId>io.github.stepio.coffee-boots</groupId>
    <artifactId>coffee-boots</artifactId>
    <version>2.2.0</version>
</dependency>

Let's review a quick example to understand what the project does:

  1. Suppose you use Spring Cache functionality much and have a set of named caches.
    • Your cached method may look like this:
@CachePut("myCache")
public Object getMyCachecObject() {
    // some heavy stuff here
}
  1. Now you know that you need an ability to configure some of the named caches with specific parameters.
    • Using this project's API you may define your own Caffeine the following way:
@Autowired
private CaffeineSupplier caffeineSupplier;

@PostConstruct
public void initialize() {
    Caffeine<Object, Object> myCacheBuilder = Caffeine.<Object, Object>newBuilder()
            .expireAfterWrite(1L, TimeUnit.MINUTES)
            .maximumSize(100000L);
    this.caffeineSupplier.putCaffeine("myCache", myCacheBuilder);
}
  1. But in most cases hard-coding the exact caching parameters is not a good idea, so you may get them from properties.
    • Modifying the above given code to get the caching parameters from Environment:
@Autowired
private CaffeineSupplier caffeineSupplier;
@Autowired
private Environment environment;

@PostConstruct
public void initialize() {
    Caffeine<Object, Object> myCacheBuilder = Caffeine.<Object, Object>newBuilder()
            .expireAfterWrite(environment.getProperty("myCache.expireAfterWrite", Long.class, 1L), TimeUnit.MINUTES)
            .maximumSize(environment.getProperty("myCache.maximumSize", Long.class, 100000L));
    this.caffeineSupplier.putCaffeine("myCache", myCacheBuilder);
}
  1. After adding 3-5 caches you understand that configuring them this way 1 by 1 is no fun. As an experienced Spring Boot user you don't want to hard-code it, you want the framework to do this little magic for you, cause you know that the case is so simple and straight-forward. Ok, you're right, you may remove the above given customizations and just define the needed value for coffee-boots.cache.spec.<your_cache_name> property.
    • The appropriate configuration in your application.properties for the above given example would be the following:
coffee-boots.cache.spec.myCache=maximumSize=100000,expireAfterWrite=1m
  1. Let's imagine that you don't need to use the project anymore. Ok, no problem:
    • At first you may remove the relevant customizations - if no code changes were introduced, just remove all the properties matching coffee-boots.* prefix. At this point your goal is reached as Coffee Boots uses Spring's default functionality if no customizations are defined.
    • If you're not planning to use this functionality in the nearest future, just drop the dependency to io.github.stepio.coffee-boots:coffee-boots artifact. Nobody needs unused dependencies.

Bonus points for advanced users

  1. If you use Caffeine only with specific environments (profiles) and don't want this project's beans to be created in other cases you can define property spring.cache.type. This project works only in 2 cases:
    • if property spring.cache.type is set with value caffeine;
    • if property spring.cache.type is not defined at all.

More information is in issue#44 or commit#a134dc6.

  1. Use coffee-boots.cache.default-spec to define "basic" cache configuration with common key-value pairs to be reused by all other custom cache configurations. This allows simplifying custom configurations if necessary.

More information is in issue#43 or commit#2a38d5b.

  1. If you'd like to get automatic metrics registaration for your custom caches, don't forget to add next dependencies:
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>

This triggers the appropriate auto-configurations with relevant post-processing, more information is in issue#38 or commit#d4f137b.

  1. You may dislike the fact that project-specific CacheManager is created alongside with the built-in Spring Boot CacheManager. "Overloaded" bean is marked as @Primary. This minor overhead allows executing the whole Spring Boot mechanism of cache initialization, including creation of CacheMetricsRegistrar bean. Individual configurations cannot be invoked as they're package-private. Project-specific deep custom configuration is avoided at all costs to simplify support of newer versions of Spring and Spring Boot.

You may still use earlier version 2.0.0 without the above mentioned advanced features if you really hate this overhead.

More information is in issue#38 or commit#d4f137b.

P.S.

Project's name is almost meaningless - just wanted it to be close to Caffeine and Spring Boot without violating 3rd party trade marks.

Related issues:

Example project (my own sandbox): stepio/coffee-boots-example.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].