MemoizationCacheInterface Class Reference

#include <memoizationcache.h>

Detailed Description

Allows to store objects for possible reuse within a global cache. All functions are thread safe.

Static Public Member Functions

static MAXON_METHOD Result< GenericDataRefGet (LiteralId &&type, const void *documentRelated, Int runId, UniqueHash hash, const Delegate< Result< GenericDataRef >()> &lambda, Bool &created=BoolLValue())
 
static MAXON_METHOD void FlushAll (LiteralId &&type, const void *documentRelated, Int removeRunId)
 
static MAXON_METHOD Result< void > GetStatistics (HashMap< Id, Tuple< Int, Int >> &result)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (MemoizationCacheInterface, MAXON_REFERENCE_STATIC, "net.maxon.command.interface.memoizationcache")
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( MemoizationCacheInterface  ,
MAXON_REFERENCE_STATIC  ,
"net.maxon.command.interface.memoizationcache"   
)
private

◆ Get()

static MAXON_METHOD Result<GenericDataRef> Get ( LiteralId &&  type,
const void *  documentRelated,
Int  runId,
UniqueHash  hash,
const Delegate< Result< GenericDataRef >()> &  lambda,
Bool created = BoolLValue() 
)
static

Gets or creates a object. If the object is not cached the lambda is called to create a new object. The caller is responsible to clone the data from the GenericData of the result.

Parameters
[in]typeCategory of the cache. See MemoizationTypes::...
[in]documentRelatedPointer to an object (e.g. BaseDocument) to which the object belongs to.
[in]runIdTimestamp of the cache object. In cc4d you can use BaseDocument::GetCacheRunId() to pass the value.
[in]hashUnique hash of the cache object.
[in]lambdaDelegate which is called to create an object if no cache was found for the given hash.
[out]createdReturns True if no cache was found and the object was created.
Returns
GenericData on success. This points to the original data. The caller is responsible to clone the data.

◆ FlushAll()

static MAXON_METHOD void FlushAll ( LiteralId &&  type,
const void *  documentRelated,
Int  removeRunId 
)
static

Flushes the caches. The caller can flush all by giving default parameters of selective by id or pointer.

Parameters
[in]typeIf type.IsPopulated() the Flush function selects only the given types.
[in]documentRelatedIf documentRelated != nullptr the function deletes only caches belonging to this pointer.
[in]removeRunIdIf removeRunId != NOTOK all values older or equal to this runId are deleted.

◆ GetStatistics()

static MAXON_METHOD Result<void> GetStatistics ( HashMap< Id, Tuple< Int, Int >> &  result)
static

Returns the current cache usage by type, count etc.

Parameters
[out]resultThe given HashMap is filled in the function call. LiteralId - the MemoizationTypes::..., Int cnt - the number of entries of the cache, Int mem - memory usage by this entry.
Returns
OK on success.