Class lsst::utils::Cache¶
-
template<typename
Key
, typenameValue
, typenameKeyHash
, typenameKeyPred
>
classCache
¶ Cache of most recently used values
This object stores the most recent
maxElements
values, wheremaxElements
is set in the constructor. Objects (of typeValue
) are stored by a key (of typeKey
; hence the need to provide aKeyHash
andKeyPred
), and the class presents a dict-like interface. Objects may be added to (add
) and retrieved from (operator[]
) the cache. For ease of use, an interface (operator()
) is also provided that will check the cache for an existing key, and if the key is not present, generate it with a function provided by the user.- Note
Value
andKey
must be copyable.- Note
This header (
Cache.h
) should generally only be included in source files, not other header files, because you probably don’t want all of theboost::multi_index
includes in your header. We suggest you se theCacheFwd.h
file in your header instead, and hold theCache
as astd::unique_ptr
.- Note
Python bindings (for pybind11) are available in
lsst/utils/python/Cache.h
.