{"id":24871217,"url":"https://github.com/philkes/spring-cache-refresh-annotation","last_synced_at":"2025-10-11T10:14:35.602Z","repository":{"id":198863390,"uuid":"698546285","full_name":"PhilKes/spring-cache-refresh-annotation","owner":"PhilKes","description":"@CacheableAutoRefreshed to combine Spring's @Cacheable and @Scheduled to automatically refresh cashes","archived":false,"fork":false,"pushed_at":"2023-10-07T11:11:17.000Z","size":100,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T22:46:22.075Z","etag":null,"topics":["caffeine","spring-boot","spring-cache","spring-scheduling"],"latest_commit_sha":null,"homepage":"","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/PhilKes.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,"governance":null}},"created_at":"2023-09-30T08:31:17.000Z","updated_at":"2023-10-07T10:22:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"96d8be89-f0c8-453b-8bf0-f323f7deef0f","html_url":"https://github.com/PhilKes/spring-cache-refresh-annotation","commit_stats":null,"previous_names":["philkes/spring-cache-refresh-annotation"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/PhilKes/spring-cache-refresh-annotation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilKes%2Fspring-cache-refresh-annotation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilKes%2Fspring-cache-refresh-annotation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilKes%2Fspring-cache-refresh-annotation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilKes%2Fspring-cache-refresh-annotation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PhilKes","download_url":"https://codeload.github.com/PhilKes/spring-cache-refresh-annotation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilKes%2Fspring-cache-refresh-annotation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271755407,"owners_count":24815398,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","spring-boot","spring-cache","spring-scheduling"],"created_at":"2025-02-01T04:31:23.422Z","updated_at":"2025-10-11T10:14:30.569Z","avatar_url":"https://github.com/PhilKes.png","language":null,"readme":"# Spring Cache-refresh Annotation\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.philkes/spring-cache-refresh-annotation/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.philkes/spring-cache-refresh-annotation)\n[![License](https://img.shields.io/badge/License-Apache--2.0-blue)](./LICENSE)\n\nThis Spring library provides the [CacheableAutoRefreshed](./src/main/java/io/github/philkes/spring/cache/annotation/CacheableAutoRefreshed.java) annotation which extends the functionality of Spring's [Cacheable](https://www.baeldung.com/spring-cache-tutorial#1-cacheable) annotation, to automatically refresh the cache at a specified point/interval in time.\n\n## Usage\n1. Scheduling has to be enabled (see [Enable Support for Scheduling](https://www.baeldung.com/spring-scheduled-tasks#enable-support-for-scheduling))\n2. Caching has to be enabled (see [Enable Caching](https://www.baeldung.com/spring-cache-tutorial#enable-caching))\n3. Add the dependency to your `pom.xml`:\n    ```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003eio.github.philkes\u003c/groupId\u003e\n        \u003cartifactId\u003espring-cache-refresh-annotation\u003c/artifactId\u003e\n        \u003cversion\u003e1.0.0\u003c/version\u003e\n    \u003c/dependency\u003e\n    ```\n   _Note: The needed Spring Beans are autoconfigured by [CacheableAutoRefreshedConfiguration](./src/main/java/io/github/philkes/spring/cache/CacheableAutoRefreshedConfiguration.java)_\n4. Annotate a method with the `@CacheableAutoRefreshed` annotation (see e.g. [TestBean](./src/test/java/io/github/philkes/spring/cache/annotation/TestBean.java)):\n   ```java\n    @CacheableAutoRefreshed(cacheNames = \"someCache\", fixedDelay = 10000)\n    public String fetchSomeData(String parameter) {\n        return someService.fetchData(parameter);\n    }\n   ```\n   In this example `fetchSomeData` return values will be cached with the default behaviour of `@Cacheable` and the cached values will be refreshed every 10 seconds.\n\n   The cache stays stable even while refreshing.\n\n## Supported Caches\n* Spring's [Simple Caching](https://docs.spring.io/spring-boot/docs/current/reference/html/io.html#io.caching.provider.simple) with `ConcurrentHashMap` (synchronously reloads all cached entries)\n* [Caffeine](https://docs.spring.io/spring-boot/docs/current/reference/html/io.html#io.caching.provider.caffeine) (utilizes the async reloading of all cache entries via [LoadingCache.refreshAll()](https://javadoc.io/doc/com.github.ben-manes.caffeine/caffeine/latest/com.github.benmanes.caffeine/com/github/benmanes/caffeine/cache/LoadingCache.html))\n* TODO: Redis\n* TODO: JCache\n\n### Configuration\nTo configure the caching itself, the `@CacheableAutoRefresh` provides the same annotation parameters as `@Cacheable` (see [Spring/Cacheable](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/annotation/Cacheable.html)) as well as all the parameters from the `@Scheduled` annotation (see [Spring/Scheduled](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html)), to specify when the cache should be refreshed (e.g. via a duration interval, cron expression)\n\n\n## Dependencies\n- Built with Java 17\n- [Spring-Framework](https://docs.spring.io/spring-framework/reference/overview.html) for `spring-context`, `spring-boot-autoconfigure`\n- [Mockito](https://site.mockito.org/) for mocking tests\n- [Awaitility](https://github.com/awaitility/awaitility) for testing spring scheduled tasks\n\n\nThis project is licensed under the terms of the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0.txt).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilkes%2Fspring-cache-refresh-annotation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilkes%2Fspring-cache-refresh-annotation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilkes%2Fspring-cache-refresh-annotation/lists"}