Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
bhuism committed Jul 11, 2020
1 parent 4059286 commit ecfa173
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/main/java/nl/appsource/badge/expected/GitHubImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ public BadgeStatus getBadgeStatus(final String owner, final String repo, final S
final BadgeStatus cacheValue = cache.getIfPresent(getKey(owner, repo, branch, commit_sha));

if (cacheValue != null) {
log.info("Cache hit");
return cacheValue;
} else {
log.info("Cache miss");
return callGitHub(owner, repo, branch, commit_sha);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/nl/appsource/badge/expected/GitLabImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public BadgeStatus getBadgeStatus(final String id, final String branch, final St
final BadgeStatus cacheValue = cache.getIfPresent(getKey(id, branch, commit_sha));

if (cacheValue != null) {
log.info("Cache hit");
return cacheValue;
} else {
log.info("Cache miss");
return callGitLab(id, branch, commit_sha);
}

Expand Down
22 changes: 10 additions & 12 deletions src/main/java/nl/appsource/badge/expected/MyCacheImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

@Slf4j
public class MyCacheImpl<K, V> implements MyCache<K, V> {
Expand All @@ -16,20 +15,19 @@ public class MyCacheImpl<K, V> implements MyCache<K, V> {

@Override
public V getIfPresent(final K key) {

synchronized (this) {

final Long expired = System.currentTimeMillis() + (EXPIRED_IN_SECONDS * 1000);

_timestamp.keySet().removeAll(
_timestamp
.entrySet()
.stream()
.filter(e -> e.getValue() < expired)
.map(Entry::getKey)
.map(_cache::remove)
.collect(Collectors.toSet()))
;
final Long expired = System.currentTimeMillis() - (EXPIRED_IN_SECONDS * 1000);

_timestamp
.entrySet()
.stream()
.filter(e -> e.getValue() < expired)
.map(Entry::getKey)
.forEach(_cache::remove);
}

return _cache.get(key);
}

Expand Down

0 comments on commit ecfa173

Please sign in to comment.