|
Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
|
Thread-safe LRU cache storing per-atom parameters or descriptors for up to N trajectory frames, bounded by both frame count and a configurable memory byte budget. More...
#include <SteinhardtLRUCache.hpp>

Classes | |
| struct | CacheEntry |
Public Types | |
| using | ParamsPtr = std::shared_ptr<const ValueType> |
Public Member Functions | |
| ThreadSafeLRUCache (std::size_t max_capacity=512, std::size_t max_bytes=kDefaultMaxBytes) noexcept | |
| Constructs cache with specified maximum frame capacity and memory byte budget. | |
| ~ThreadSafeLRUCache ()=default | |
| ThreadSafeLRUCache (const ThreadSafeLRUCache &)=delete | |
| ThreadSafeLRUCache & | operator= (const ThreadSafeLRUCache &)=delete |
| ThreadSafeLRUCache (ThreadSafeLRUCache &&) noexcept=delete | |
| ThreadSafeLRUCache & | operator= (ThreadSafeLRUCache &&) noexcept=delete |
| ParamsPtr | get (std::size_t frame_index) |
| Retrieves cached parameters and marks frame as most recently used. | |
| ParamsPtr | peek (std::size_t frame_index) const |
| Inspects cache for frame without updating LRU order. | |
| void | put (std::size_t frame_index, ParamsPtr params) |
| Inserts or updates cached parameters for a frame. | |
| bool | contains (std::size_t frame_index) const |
| Checks if a given frame index resides in the cache. | |
| std::size_t | size () const |
| Gets current count of cached frames. | |
| std::size_t | capacity () const noexcept |
| Gets maximum frame capacity of the cache. | |
| void | setCapacity (std::size_t new_capacity) |
| Updates maximum frame capacity, evicting oldest entries if shrinking. | |
| std::size_t | memoryBytes () const noexcept |
| Gets current estimated memory footprint of cached entries in bytes. | |
| std::size_t | maxBytes () const noexcept |
| Gets configured maximum byte budget (0 indicates unlimited). | |
| void | setMaxBytes (std::size_t new_max_bytes) |
| Updates the byte budget, evicting oldest entries if over budget. | |
| template<typename Pred> | |
| std::size_t | countMatching (Pred &&pred) const |
| Counts cached entries satisfying a predicate. | |
| void | clear () |
| Purges all entries from the cache. | |
Static Public Attributes | |
| static constexpr std::size_t | kDefaultMaxBytes = 256UL * 1024UL * 1024UL |
| 256 MiB cap. | |
Private Member Functions | |
| void | evictIfNeededLocked () |
Private Attributes | |
| std::shared_mutex | mutex_ |
| std::size_t | capacity_ {512} |
| std::size_t | max_bytes_ {kDefaultMaxBytes} |
| std::size_t | current_bytes_ {0} |
| std::list< std::size_t > | lru_order_ |
| std::unordered_map< std::size_t, CacheEntry > | map_ |
Thread-safe LRU cache storing per-atom parameters or descriptors for up to N trajectory frames, bounded by both frame count and a configurable memory byte budget.
Utilizes std::shared_mutex to permit concurrent read queries while synchronizing LRU mutations and evictions under write locks.
| using correlation::app::ThreadSafeLRUCache< ValueType >::ParamsPtr = std::shared_ptr<const ValueType> |
|
inlineexplicitnoexcept |
Constructs cache with specified maximum frame capacity and memory byte budget.
| [in] | max_capacity | Maximum number of frames cached simultaneously (default 512). |
| [in] | max_bytes | Maximum resident byte budget (default 256 MiB; 0 disables byte cap). |
|
default |
|
delete |
|
deletenoexcept |
|
inlinenodiscardnoexcept |
Gets maximum frame capacity of the cache.
|
inline |
Purges all entries from the cache.
|
inlinenodiscard |
Checks if a given frame index resides in the cache.
| [in] | frame_index | Trajectory frame index. |
|
inlinenodiscard |
Counts cached entries satisfying a predicate.
| Pred | Callable taking const ValueType & and returning bool. |
| [in] | pred | Predicate evaluated on each non-null cached value. |
|
inlineprivate |

|
inlinenodiscard |
Retrieves cached parameters and marks frame as most recently used.
| [in] | frame_index | Trajectory frame index. |
|
inlinenodiscardnoexcept |
Gets configured maximum byte budget (0 indicates unlimited).
|
inlinenodiscardnoexcept |
Gets current estimated memory footprint of cached entries in bytes.
|
delete |
|
deletenoexcept |
|
inlinenodiscard |
Inspects cache for frame without updating LRU order.
| [in] | frame_index | Trajectory frame index. |
|
inline |
Inserts or updates cached parameters for a frame.
| [in] | frame_index | Trajectory frame index. |
| [in] | params | Computed parameters. |
|
inline |
Updates maximum frame capacity, evicting oldest entries if shrinking.
| [in] | new_capacity | New maximum frame count (clamped to >= 1). |
|
inline |
Updates the byte budget, evicting oldest entries if over budget.
| [in] | new_max_bytes | New byte budget (0 disables byte cap). |
|
inlinenodiscard |
Gets current count of cached frames.
|
private |
|
private |
|
staticconstexpr |
256 MiB cap.
|
private |
|
private |
|
private |
|
mutableprivate |