-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use expiring cache to keep measurements.
- Loading branch information
Showing
6 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
verkeersdrukte/src/main/java/nl/bertriksikken/verkeersdrukte/traffic/MeasurementCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package nl.bertriksikken.verkeersdrukte.traffic; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import com.google.common.cache.Cache; | ||
import com.google.common.cache.CacheBuilder; | ||
|
||
import java.time.Duration; | ||
|
||
public final class MeasurementCache { | ||
|
||
private final Instant publishedDateTime; | ||
private Map<String, AggregateMeasurement> measurementMap = new ConcurrentHashMap<>(); | ||
private final Cache<String, AggregateMeasurement> cache; | ||
|
||
MeasurementCache(Instant publishedDateTime) { | ||
this.publishedDateTime = publishedDateTime; | ||
MeasurementCache(Duration expiryDuration) { | ||
cache = CacheBuilder.newBuilder().expireAfterWrite(expiryDuration).build(); | ||
} | ||
|
||
public void put(String location, AggregateMeasurement measurement) { | ||
measurementMap.put(location, measurement); | ||
cache.put(location, measurement); | ||
} | ||
|
||
public AggregateMeasurement get(String location) { | ||
return measurementMap.get(location); | ||
return cache.getIfPresent(location); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters