Skip to content

Commit

Permalink
Added closure arg types to Cache/CachedValue documentation (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
jskupsik authored Nov 11, 2024
1 parent b8fdc57 commit 7d740e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 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 @@ -39,25 +39,27 @@ class Cache<K, V> implements LogSupport {
/** Unique name in the context of the service associated with this object. */
public final String name

/** Closure to determine if an entry should be expired (optional). */
/**
* Closure { CacheEntry<V> -> Boolean } to determine if an entry should be expired (optional).
*/
public final Closure<Boolean> expireFn

/**
* Entry TTL as epochMillis Long, or closure to return the same (optional).
* Entry TTL as epochMillis Long, or closure { void -> Long } to return the same (optional).
* No effect if a custom expireFn is provided instead. If both null, entries will never expire.
*/
public final Object expireTime

/**
* Closure to determine the timestamp of an entry (optional).
* Closure { V -> Long | Date | Instant } to determine the timestamp of an entry (optional).
* Must return a Long (as epochMillis), Date, or Instant.
*/
public final Closure timestampFn

/** True to replicate this cache across a cluster (default false). */
public final boolean replicate

/** Handlers to be called on change with a {@link CacheEntryChanged} */
/** Handler closures { CacheEntryChanged<K, V> -> void } to be called on change. */
public final List<Closure> onChange = []

/**
Expand Down
11 changes: 7 additions & 4 deletions src/main/groovy/io/xh/hoist/cachedvalue/CachedValue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,28 @@ class CachedValue<V> implements LogSupport {
/** Unique name in the context of the service associated with this object. */
public final String name

/** Closure to determine if an entry should be expired (optional). */
/**
* Closure { CachedValueEntry<V> -> Boolean } to determine if an entry should
* be expired (optional).
*/
public final Closure<Boolean> expireFn

/**
* Entry TTL as epochMillis Long, or closure to return the same (optional).
* Entry TTL as epochMillis Long, or closure { void -> Long } to return the same (optional).
* No effect if a custom expireFn is provided instead. If both null, entries will never expire.
*/
public final Object expireTime

/**
* Closure to determine the timestamp of an entry (optional).
* Closure { V -> Long | Date | Instant } to determine the timestamp of an entry (optional).
* Must return a Long (as epochMillis), Date, or Instant.
*/
public final Closure timestampFn

/** True to replicate this cache across a cluster (default false). */
public final boolean replicate

/** Handlers to be called on change with a {@link CachedValueChanged} object. */
/** Handler closures { CachedValueChanged<V> -> void } to be called on change. */
public final List<Closure> onChange = []


Expand Down

0 comments on commit 7d740e7

Please sign in to comment.