Skip to content

Commit

Permalink
+ Add Groovy truth to Cache and CachedValue.
Browse files Browse the repository at this point in the history
+ Include size of collection for cached value
  • Loading branch information
lbwexler committed Sep 17, 2024
1 parent 675bfc3 commit d293341
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/main/groovy/io/xh/hoist/cache/Cache.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class Cache<K, V> extends BaseCache<V> {
onChange << handler
}


/**
* Wait for the cache entry to be populated.
* @param key - entry to check
Expand All @@ -156,6 +155,9 @@ class Cache<K, V> extends BaseCache<V> {
}
}

//------------------------
// Implementation
//------------------------
Map getAdminStats() {
[
name : name,
Expand All @@ -166,10 +168,10 @@ class Cache<K, V> extends BaseCache<V> {
]
}

boolean asBoolean() {
return size() > 0
}

//------------------------
// Implementation
//------------------------
private void cullEntries() {
Set<K> cullKeys = new HashSet<>()
def oldSize = size()
Expand Down
22 changes: 17 additions & 5 deletions src/main/groovy/io/xh/hoist/cache/CachedValue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,23 @@ class CachedValue<V> extends BaseCache<V> {
onChange << handler
}

//-------------------
// Implementation
//-------------------
Map getAdminStats() {
[
name : name,
type : 'CachedValue' + (replicate ? ' (replicated)' : ''),
timestamp: timestamp
]
def val = get(),
ret = [
name : name,
type : 'CachedValue' + (replicate ? ' (replicated)' : ''),
timestamp: timestamp
]
if (val instanceof Collection) {
ret.size = val.size()
}
return ret
}

boolean asBoolean() {
return get() != null
}
}

0 comments on commit d293341

Please sign in to comment.