Caching AWS Session Object using Spring Cache

Getting Started

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.google.guava:guava:31.0.1-jre'
}

Creating the Cache Configuration

@EnableCaching
@Configuration
public class CacheConfiguration implements CachingConfigurer {

@Override
public CacheManager cacheManager() {

ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager() {

@Override
protected Cache createConcurrentMapCache(final String name) {
return new ConcurrentMapCache(name,
CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES).maximumSize(100).build().asMap(), false);
}
};

return cacheManager;
}
}

Caching with Annotation

@Cacheable("iamClient")
public IamClient iamClient(AmazonSessionMapper amazonSessionMapper) {
.............................
return iamClient;
}

Summary

--

--

--

9+ years of experience in building product related to private datacenter and public cloud #Java #AWS #VMware #Python

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vignesh A Sathiyanantham

Vignesh A Sathiyanantham

9+ years of experience in building product related to private datacenter and public cloud #Java #AWS #VMware #Python

More from Medium

Example of Spring Cloud Function with AWS Lambda

How to Deploy SpringBoot App to Elastic Beanstalk Using Github Actions CI/CD

How to Deploy a SpringBoot App to AWS Elastic Beanstalk

Containerization of spring-boot microservices using docker (Part 1/3)