Skip to content

kimwz/caffeine-cache-annotation

Repository files navigation

A sample code using Caffeine Cache through Annotation in Spring

Usage

@Service
public class TimeService {

	@SimpleCaffeineCache(name = "getNowCache", expireAfterWrite = 20, refreshAfterWrite = 5)
	public String getNow(String name) throws InterruptedException {
		Thread.sleep(3000);
		return name + " / " + DateTime.now().toString();
	}
	
}

Setting

build.gradle

repositories {
    maven {
        url "https://github.com/kimwz/caffeine-cache-annotation/raw/master/release/"
    }
}

compile('com.github.kimwz.caffeinecache:caffeinecache-annotation:1.0')

// default dependencies
compile('org.aspectj:aspectjweaver:1.8.6')
compile("com.github.ben-manes.caffeine:caffeine:2.3.1")

CacheConfig.java

@Configuration
@EnableAspectJAutoProxy
public class CacheConfig {
	@Bean
	public SimpleCaffeineCacheAspect simpleCaffeineCache() {
		return new SimpleCaffeineCacheAspect();
	}
}

About

A Simple Caffeine Cache Annotation in Spring

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages