Assuming you use Spring Security as part of your app, it should be managing your session, and every time you log out, it will create a new session. Unless you had posted this code, I'm not going to be able to help you there. However, assuming you can log in/out, this should be covered already.
As for the cacheing, in general, this sounds like a Database Caching need, which is something that you would use Spring Boot Caching on.
To use this in Spring Boot, you would add the following dependency to maven (or the equivalent in Gradle, etc):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
- Adjust your application to allow using Cacheing, which can be done by adding the annotation
@EnableCaching
to your Spring Boot application
@SpringBootApplication
@EnableCaching
public class MyApplication {
...
}
- Create a Java Service Object, called something like MessagesService.class:
@CacheConfig(cacheNames={"Messages"})
public class MessagesService {
@Cacheable(value="cacheMessages")
List<String> getMessages() {
//access the database to load data here
...
}
...
}