Skip to content

PhilKes/spring-cache-refresh-annotation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Cache-refresh Annotation

Maven Central License

This Spring library provides the CacheableAutoRefreshed annotation which extends the functionality of Spring's Cacheable annotation, to automatically refresh the cache at a specified point/interval in time.

Usage

  1. Scheduling has to be enabled (see Enable Support for Scheduling)

  2. Caching has to be enabled (see Enable Caching)

  3. Add the dependency to your pom.xml:

    <dependency>
        <groupId>io.github.philkes</groupId>
        <artifactId>spring-cache-refresh-annotation</artifactId>
        <version>1.0.0</version>
    </dependency>

    Note: The needed Spring Beans are autoconfigured by CacheableAutoRefreshedConfiguration

  4. Annotate a method with the @CacheableAutoRefreshed annotation (see e.g. TestBean):

     @CacheableAutoRefreshed(cacheNames = "someCache", fixedDelay = 10000)
     public String fetchSomeData(String parameter) {
         return someService.fetchData(parameter);
     }

    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.

    The cache stays stable even while refreshing.

Supported Caches

Configuration

To configure the caching itself, the @CacheableAutoRefresh provides the same annotation parameters as @Cacheable (see Spring/Cacheable) as well as all the parameters from the @Scheduled annotation (see Spring/Scheduled), to specify when the cache should be refreshed (e.g. via a duration interval, cron expression)

Dependencies

This project is licensed under the terms of the Apache 2.0 license.

About

@CacheableAutoRefreshed to combine Spring's @Cacheable and @scheduled to automatically refresh cashes

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published