最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Efficiently Implementing a Periodic In-Memory Refresh Mechanism in a Spring Application, suggest for my requirement - Sta

programmeradmin1浏览0评论

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:

  1. Detect changes in the existing files or identify new files.
  2. 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:

  1. Is my idea of using @Scheduled efficient for this use case?
  2. Are there better approaches to detect file changes or additions in the MinIO bucket without scanning all files at each interval?
  3. How can I minimize the performance overhead while ensuring the memory is always updated with the latest data?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论