Skip to content

Commit

Permalink
Add cache size operation. (#23)
Browse files Browse the repository at this point in the history
Add getCacheSize(orgId) to CacheService.

This should be a (slight) performance improvement as REST controllers start using this instead of retrieveing all items only to count them.
  • Loading branch information
Asgeir Storesund Nilsen authored Jan 28, 2020
1 parent 0585aa3 commit 57bb63c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/no/fint/cache/CacheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public long getLastUpdated(String orgId) {
return getCache(orgId).map(Cache::getLastUpdated).orElseThrow(() -> new CacheNotFoundException(orgId));
}

public long getCacheSize(String orgId) {
return getCache(orgId).map(Cache::size).orElseThrow(() -> new CacheNotFoundException(orgId));
}

public Optional<Cache<T>> getCache(String orgId) {
return cacheManager.getCache(CacheUri.create(orgId, model));
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/groovy/no/fint/cache/FintCacheIntegrationSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ class FintCacheIntegrationSpec extends Specification {
lastUpdated > 0L
}

def "Get cache size"() {
when:
def size = testCacheService.getCacheSize('rogfk.no')

then:
size == 2
}

def "Update cache, add new value"() {
when:
testCacheService.update('rogfk.no', ['test1', 'test2', 'test3'])
Expand Down

0 comments on commit 57bb63c

Please sign in to comment.