Add configuration cache
Problem Context
Loading configuration from external service is slow. We want to cache it and only load once.
Advanced
200 points
File Changes (1)
src/main/java/com/example/config/ConfigurationCache.java
ADDED
@@ -0 +1 @@
| 1 | +package com.example.config; |
|
| 2 | + |
|
| 3 | +import org.springframework.stereotype.Component; |
|
| 4 | + |
|
| 5 | +@Component |
|
| 6 | +public class ConfigurationCache { |
|
| 7 | + |
|
| 8 | + private final ConfigurationService configService; |
|
| 9 | + private AppConfiguration cachedConfig; |
|
| 10 | + |
|
| 11 | + public ConfigurationCache(ConfigurationService configService) { |
|
| 12 | + this.configService = configService; |
|
| 13 | + } |
|
| 14 | + |
|
| 15 | + public AppConfiguration getConfiguration() { |
|
| 16 | + if (cachedConfig == null) { |
|
| 17 | + // Load from external service (expensive operation) |
|
| 18 | + cachedConfig = configService.loadFromExternalService(); |
|
| 19 | + } |
|
| 20 | + return cachedConfig; |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public void refreshConfiguration() { |
|
| 24 | + cachedConfig = null; |
|
| 25 | + } |
|
| 26 | +} |
Login Required: You must be registered to submit reviews and receive AI feedback.
Register or
login to start reviewing!
Your Review
Review Tips
- Look for security vulnerabilities (SQL injection, XSS, etc.)
- Check for null pointer exceptions and error handling
- Consider performance implications
- Evaluate code maintainability and readability
- Check for proper resource management
- Look for logic errors or edge cases