MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
RegionCacheManager.hpp
Go to the documentation of this file.
1#pragma once
2#include "RegionSegment.hpp"
3
4namespace MayaFlux::Kakshya {
5
6struct RegionHash {
7 std::size_t operator()(const Region& region) const;
8};
9
10/**
11 * @class RegionCacheManager
12 * @brief Manages caching of region data for efficient access and eviction.
13 *
14 * Provides LRU-based caching for RegionCache and RegionSegment objects,
15 * supporting efficient repeated/random access to region data.
16 */
17class MAYAFLUX_API RegionCacheManager {
18 std::unordered_map<Region, RegionCache, RegionHash> m_cache;
19 std::list<Region> m_lru_list;
21 size_t m_current_size = 0;
22 bool m_initialized = false;
23 mutable std::recursive_mutex m_mutex;
24
25 void evict_lru_if_needed();
26 std::optional<RegionCache> get_cached_region_internal(const Region& region);
27 void update_lru(const Region& region);
28
29public:
30 explicit RegionCacheManager(size_t max_size);
32
35
37 RegionCacheManager& operator=(RegionCacheManager&&) noexcept = delete;
38
39 /**
40 * @brief Initialize the cache manager.
41 */
42 inline void initialize() { m_initialized = true; }
43 /**
44 * @brief Check if the cache manager is initialized.
45 */
46 inline bool is_initialized() const { return m_initialized; }
47
48 void cache_region(const RegionCache& cache);
49 void cache_segment(const RegionSegment& segment);
50 std::optional<RegionCache> get_cached_region(const Region& region);
51 std::optional<RegionCache> get_cached_segment(const RegionSegment& segment);
52 std::optional<RegionSegment> get_segment_with_cache(const RegionSegment& segment);
53 void clear();
54 size_t size() const;
55 size_t max_size() const;
56};
57}
RegionCacheManager(RegionCacheManager &&) noexcept=delete
RegionCacheManager(const RegionCacheManager &)=delete
RegionCacheManager & operator=(const RegionCacheManager &)=delete
std::unordered_map< Region, RegionCache, RegionHash > m_cache
bool is_initialized() const
Check if the cache manager is initialized.
Manages caching of region data for efficient access and eviction.
void initialize()
Definition main.cpp:11
Stores cached data for a region, with metadata for cache management.
std::size_t operator()(const Region &region) const
Represents a discrete segment of audio data with caching capabilities.
Represents a point or span in N-dimensional space.
Definition Region.hpp:67