The requirement for my project is to introduce a refresh mechanism for in-memory data at specific time intervals in a Spring application. The details are as follows:
The application uses a MinIO server (S3 Object Storage) where JSON files are stored.
These files need to be loaded into memory in a Map<String, Map<String, Object>>
format before the application starts. This is currently implemented using the @PostConstruct
annotation.
Now, the project requires introducing a refresh mechanism for the memory. Moving forward, the application must refresh this in-memory data at regular intervals (e.g., every 5 minutes) to reflect: Changes made to existing files.
Addition of new files in the MinIO bucket. The refresh should be efficient and should not require restarting the entire Spring application.
I implemented the initial file-loading mechanism using the @PostConstruct
annotation, which successfully loads the files into memory during application startup.
For the refresh mechanism, my initial idea was to use Spring's @Scheduled annotation to periodically check the MinIO bucket every 5 minutes.
The task would:
- Detect changes in the existing files or identify new files.
- Update the in-memory
Map<String, Map<String, Object>>
with the modified or new data.
I'm expecting a solution or confirmation on the best way to implement this refresh mechanism. Specifically:
- Is my idea of using
@Scheduled
efficient for this use case? - Are there better approaches to detect file changes or additions in the MinIO bucket without scanning all files at each interval?
- How can I minimize the performance overhead while ensuring the memory is always updated with the latest data?