Template Class DataCache#
Defined in File DataCache.h
Inheritance Relationships#
Base Type#
public Karana::Core::LockingBase(Class LockingBase)
Class Documentation#
-
template<class T>
class DataCache : public Karana::Core::LockingBase# A cache for managing a value of type
Twith a stale flag mechanism.The
DataCacheclass provides the following features:Caches a value of type
T.Marks the value as stale when certain conditions are met.
Provides a callback mechanism to refresh the cached value.
Supports registering dependent “child” caches that are marked stale when the parent cache becomes stale.
- Template Parameters:
T – The type of the cached value.
Public Functions
-
inline DataCache(std::string_view name, const std::function<void(T&)> &callback, std::optional<std::string> type_string = std::nullopt)#
Constructs a
DataCacheobject.- Parameters:
name – The name of the cache.
callback – A callback function to refresh the cached value when it becomes stale.
type_string – An optional string representation of the type
T.
-
inline const T &get()#
Retrieves the cached value.
If the cached value is not stale, it returns the current value. If the value is stale, the callback function is called to refresh the value, and the refreshed value is returned.
- Returns:
A const reference to the cached value.
-
inline void setCallback(const std::function<void(T&)> &callback)#
Set the callback method for the class.
This method is handy for deferred setting of the callback method when the method is not available (or perhaps its closures are not available) at the time the cache is constructed.
- Parameters:
callback – The callback to set as this DataCache’s callback.
-
inline void updateDataBuffer(const std::function<void(T&)> &callback)#
Invoke the callback on the cached value to set it up.
This method is handy for cases when the cached value needs to modified in some way, such as to resize a vector or matrix in the beginning.
- Parameters:
callback – The callback to use to update the data buffer.
-
inline const T &getRaw() const#
Retrieves the raw cached value - without triggering updates.
This method directly returns the cached value withoug triggering updates (such as by the get() method when the cache value happens to be stale).
- Returns:
A const reference to the cached value.
-
inline virtual std::string_view typeString() const noexcept override#
Returns the type string of LockingBase.
This version returns a non-const version. This is needed to pre-set additional data in the these cached buffers (eg. list of onodes in the pnode buffer) that will be needed at run-time by the cache
- Returns:
The type string.