{"id":17039800,"url":"https://github.com/stepio/coffee-boots","last_synced_at":"2025-07-10T11:10:21.434Z","repository":{"id":34294746,"uuid":"164026061","full_name":"stepio/coffee-boots","owner":"stepio","description":"Support property-based configuring of multiple Caffeine caches for Spring Cache abstraction.","archived":false,"fork":false,"pushed_at":"2023-06-13T03:57:43.000Z","size":162,"stargazers_count":36,"open_issues_count":13,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T08:47:42.319Z","etag":null,"topics":["caffeine","environment","java","spring","spring-boot","spring-cache"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stepio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-03T21:43:19.000Z","updated_at":"2025-01-27T23:17:44.000Z","dependencies_parsed_at":"2023-02-16T03:16:48.011Z","dependency_job_id":null,"html_url":"https://github.com/stepio/coffee-boots","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepio%2Fcoffee-boots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepio%2Fcoffee-boots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepio%2Fcoffee-boots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stepio%2Fcoffee-boots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stepio","download_url":"https://codeload.github.com/stepio/coffee-boots/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578871,"owners_count":21127713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caffeine","environment","java","spring","spring-boot","spring-cache"],"created_at":"2024-10-14T09:07:31.377Z","updated_at":"2025-04-12T14:11:59.955Z","avatar_url":"https://github.com/stepio.png","language":null,"readme":"# Coffee Boots\n\n[![Build Status](https://travis-ci.com/stepio/coffee-boots.svg?branch=master)](https://travis-ci.com/stepio/coffee-boots)\n[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=stepio_coffee-boots\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=stepio_coffee-boots)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/e3997372bb2448ebae5282fddc44784f)](https://app.codacy.com/app/stepio/coffee-boots?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=stepio/coffee-boots\u0026utm_campaign=Badge_Grade_Dashboard)\n[![DepShield Badge](https://depshield.sonatype.org/badges/stepio/coffee-boots/depshield.svg)](https://depshield.github.io)\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.stepio.coffee-boots/coffee-boots.svg)](https://mvnrepository.com/artifact/io.github.stepio.coffee-boots/coffee-boots)\n[![Javadocs](http://www.javadoc.io/badge/io.github.stepio.coffee-boots/coffee-boots.svg)](http://www.javadoc.io/doc/io.github.stepio.coffee-boots/coffee-boots)\n[![Apache 2.0 License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0.txt)\n\nCoffee Boots project implements (property-based) configuring of multiple [Caffeine](https://github.com/ben-manes/caffeine) caches for [Spring Cache](https://github.com/spring-projects/spring-framework/tree/master/spring-context/src/main/java/org/springframework/cache) abstraction. \nIt works best with [Spring Boot](https://github.com/spring-projects/spring-boot), implementing [auto-configuration](https://github.com/stepio/coffee-boots/blob/master/src/main/java/io/github/stepio/cache/caffeine/CaffeineSpecSpringAutoConfiguration.java) mechanism.\nThis means that in most cases you don't have to create any beans yourself, just add [dependency to the latest version](https://search.maven.org/search?q=g:io.github.stepio.coffee-boots%20AND%20a:coffee-boots\u0026core=gav):\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.stepio.coffee-boots\u003c/groupId\u003e\n    \u003cartifactId\u003ecoffee-boots\u003c/artifactId\u003e\n    \u003cversion\u003e2.2.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nLet's review a quick example to understand what the project does:\n1.  Suppose you use Spring Cache functionality much and have a set of named caches.\n    -   Your cached method may look like this:\n```java\n@CachePut(\"myCache\")\npublic Object getMyCachecObject() {\n    // some heavy stuff here\n}\n```\n2.  Now you know that you need an ability to configure some of the named caches with specific parameters.\n    -   Using this project's API you may define your own `Caffeine` the following way:\n```java\n@Autowired\nprivate CaffeineSupplier caffeineSupplier;\n\n@PostConstruct\npublic void initialize() {\n    Caffeine\u003cObject, Object\u003e myCacheBuilder = Caffeine.\u003cObject, Object\u003enewBuilder()\n            .expireAfterWrite(1L, TimeUnit.MINUTES)\n            .maximumSize(100000L);\n    this.caffeineSupplier.putCaffeine(\"myCache\", myCacheBuilder);\n}\n```\n3.  But in most cases hard-coding the exact caching parameters is not a good idea, so you may get them from properties.\n    -   Modifying the above given code to get the caching parameters from `Environment`:\n```java\n@Autowired\nprivate CaffeineSupplier caffeineSupplier;\n@Autowired\nprivate Environment environment;\n\n@PostConstruct\npublic void initialize() {\n    Caffeine\u003cObject, Object\u003e myCacheBuilder = Caffeine.\u003cObject, Object\u003enewBuilder()\n            .expireAfterWrite(environment.getProperty(\"myCache.expireAfterWrite\", Long.class, 1L), TimeUnit.MINUTES)\n            .maximumSize(environment.getProperty(\"myCache.maximumSize\", Long.class, 100000L));\n    this.caffeineSupplier.putCaffeine(\"myCache\", myCacheBuilder);\n}\n```\n4.  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.\nOk, you're right, you may remove the above given customizations and just define the needed value for `coffee-boots.cache.spec.\u003cyour_cache_name\u003e` property.\n    -   The appropriate configuration in your `application.properties` for the above given example would be the following:\n```properties\ncoffee-boots.cache.spec.myCache=maximumSize=100000,expireAfterWrite=1m\n```\n5.  Let's imagine that you don't need to use the project anymore. Ok, no problem:\n    -   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.\n    -   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.\n\n## Bonus points for advanced users\n\n6.  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:\n    -   if property `spring.cache.type` is set with value `caffeine`;\n    -   if property `spring.cache.type` is not defined at all.\n\nMore information is in [issue#44](https://github.com/stepio/coffee-boots/issues/44) or [commit#a134dc6](https://github.com/stepio/coffee-boots/commit/a134dc60843b46b6a69b00ce4449c510b301f534#diff-798aa55948ec42d85da39f34a917b73f).\n\n7.  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.\n\nMore information is in [issue#43](https://github.com/stepio/coffee-boots/issues/43) or [commit#2a38d5b](https://github.com/stepio/coffee-boots/commit/2a38d5b3ca7e12c2cbc152e2b5f5bf0aa3233f34#diff-a6f66d25e49c3ad808097932be3df2d0).\n\n8.  If you'd like to get automatic metrics registaration for your custom caches, don't forget to add next dependencies:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.micrometer\u003c/groupId\u003e\n    \u003cartifactId\u003emicrometer-core\u003c/artifactId\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n    \u003cartifactId\u003espring-boot-actuator-autoconfigure\u003c/artifactId\u003e\n\u003c/dependency\u003e\n```\n\nThis triggers the appropriate auto-configurations with relevant post-processing, more information is in [issue#38](https://github.com/stepio/coffee-boots/issues/38) or [commit#d4f137b](https://github.com/stepio/coffee-boots/commit/d4f137bad73a26a490ec9c2564e2ff512b2eebfe#diff-798aa55948ec42d85da39f34a917b73f).\n\n9.  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.\nIndividual 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.\n\nYou may still use earlier version `2.0.0` without the above mentioned advanced features if you really hate this overhead.\n\nMore information is in [issue#38](https://github.com/stepio/coffee-boots/issues/38) or [commit#d4f137b](https://github.com/stepio/coffee-boots/commit/d4f137bad73a26a490ec9c2564e2ff512b2eebfe#diff-798aa55948ec42d85da39f34a917b73f).\n\n## P.S.\n\nProject's name is almost meaningless - just wanted it to be close to `Caffeine` and `Spring Boot` without violating 3rd party trade marks.\n\nRelated issues:\n-   [spring-framework/pull/1506](https://github.com/spring-projects/spring-framework/pull/1506)\n-   [spring-framework/pull/1932](https://github.com/spring-projects/spring-framework/pull/1932/files)\n-   [spring-boot/issues/9301](https://github.com/spring-projects/spring-boot/issues/9301)\n\nExample project (my own sandbox): [stepio/coffee-boots-example](https://github.com/stepio/coffee-boots-example).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepio%2Fcoffee-boots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstepio%2Fcoffee-boots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstepio%2Fcoffee-boots/lists"}