CE-604 expose fetching MemoizedResult (so nulls can be cached and differentiated from not-founds)

This commit is contained in:
2023-11-01 12:11:36 -05:00
parent 8b6eb63253
commit a7d5741d1c
3 changed files with 69 additions and 2 deletions

View File

@ -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
**

View File

@ -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;