mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-20 06:00:44 +00:00
CE-604 expose fetching MemoizedResult (so nulls can be cached and differentiated from not-founds)
This commit is contained in:
@ -67,7 +67,26 @@ public class Memoization<K, V>
|
||||
{
|
||||
if(result.getTime().isAfter(Instant.now().minus(timeout)))
|
||||
{
|
||||
return (Optional.of(result.getResult()));
|
||||
return (Optional.ofNullable(result.getResult()));
|
||||
}
|
||||
}
|
||||
|
||||
return (Optional.empty());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public Optional<MemoizedResult<V>> getMemoizedResult(K key)
|
||||
{
|
||||
MemoizedResult<V> result = map.get(key);
|
||||
if(result != null)
|
||||
{
|
||||
if(result.getTime().isAfter(Instant.now().minus(timeout)))
|
||||
{
|
||||
return (Optional.ofNullable(result));
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,6 +141,16 @@ public class Memoization<K, V>
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void clear()
|
||||
{
|
||||
this.map.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for timeoutSeconds
|
||||
**
|
||||
|
@ -29,7 +29,7 @@ import java.time.Instant;
|
||||
** Object stored in the Memoization class. Shouldn't need to be visible outside
|
||||
** its package.
|
||||
*******************************************************************************/
|
||||
class MemoizedResult<T>
|
||||
public class MemoizedResult<T>
|
||||
{
|
||||
private T result;
|
||||
private Instant time;
|
||||
|
Reference in New Issue
Block a user