|
Grok 20.3.2
|
Per-file LRU cache that manages compressed tile part data in memory. More...
#include <CompressedChunkCache.h>
Classes | |
| struct | Entry |
Public Member Functions | |
| CompressedChunkCache (size_t maxBytes=0, std::shared_ptr< DiskCache > diskCache=nullptr, GRK_CODEC_FORMAT codecFormat=GRK_CODEC_J2K) | |
| Construct the cache. | |
| void | put (uint16_t tileIndex, std::shared_ptr< TPFetchSeq > seq) |
| Register a tile's fetched data with the cache. | |
| std::shared_ptr< TPFetchSeq > | get (uint16_t tileIndex) |
| Ensure a tile's compressed data is in memory. | |
| bool | contains (uint16_t tileIndex) const |
| Check if a tile is tracked (memory or disk). | |
| void | clear () |
| size_t | currentBytes () const |
| size_t | maxBytes () const |
| size_t | size () const |
Private Member Functions | |
| void | pushFrontLRU (uint16_t tileIndex) |
| void | removeLRU (uint16_t tileIndex) |
| void | promoteLRU (uint16_t tileIndex) |
| void | evictToFit () |
| void | spillToDisk (uint16_t tileIndex, Entry &entry) |
| Serialize tile part data to disk and release in-memory buffers. | |
| bool | reloadFromDisk (uint16_t tileIndex, Entry &entry) |
| Reload tile part data from disk into the existing TPFetch objects. | |
Static Private Member Functions | |
| static size_t | calcSeqDataSize (const TPFetchSeq &seq) |
| static size_t | resolveMaxBytes (size_t provided) |
| Resolve max bytes from environment or use provided value. | |
Private Attributes | |
| size_t | maxBytes_ |
| size_t | currentBytes_ |
| std::shared_ptr< DiskCache > | diskCache_ |
| GRK_CODEC_FORMAT | codecFormat_ |
| std::mutex | mutex_ |
| std::list< uint16_t > | lruList_ |
| std::unordered_map< uint16_t, std::list< uint16_t >::iterator > | lruMap_ |
| std::unordered_map< uint16_t, Entry > | entries_ |
Static Private Attributes | |
| static constexpr size_t | kDefaultMaxBytes = 256 * 1024 * 1024 |
Per-file LRU cache that manages compressed tile part data in memory.
Approach B (minimal): the cache does NOT duplicate TPFetch data. It holds shared ownership of each tile's TPFetchSeq and tracks total in-memory compressed bytes. When the high water mark is exceeded, the LRU tile's TPFetch::data_ buffers are serialized to the DiskCache and released. On reload, the buffers and mem-streams are recreated from disk.
Cache size is controlled by the GRK_CACHEMAX or GDAL_CACHEMAX environment variable. Defaults to 256 MB.
|
inlineexplicit |
Construct the cache.
| maxBytes | memory budget in bytes (0 = read from env) |
| diskCache | optional disk cache for eviction spill |
| codecFormat | codec format used to recreate mem-streams on reload |
References codecFormat_, currentBytes_, diskCache_, GRK_CODEC_J2K, maxBytes(), maxBytes_, and resolveMaxBytes().
|
inlinestaticprivate |
References grk::SharedPtrSeq< T >::size().
Referenced by put().
|
inline |
References currentBytes_, diskCache_, entries_, lruList_, lruMap_, and mutex_.
|
inline |
|
inline |
References currentBytes_, and mutex_.
|
inlineprivate |
References currentBytes_, entries_, lruList_, lruMap_, maxBytes_, and spillToDisk().
Referenced by put().
|
inline |
Ensure a tile's compressed data is in memory.
If the data was spilled to disk, it is reloaded and the TPFetch::data_ / stream_ pointers are repopulated.
References entries_, mutex_, promoteLRU(), and reloadFromDisk().
|
inline |
References maxBytes_.
Referenced by CompressedChunkCache().
|
inlineprivate |
|
inlineprivate |
|
inline |
Register a tile's fetched data with the cache.
Takes shared ownership of the TPFetchSeq. The actual byte buffers live in TPFetch::data_; we only track their sizes.
References calcSeqDataSize(), currentBytes_, grk::CompressedChunkCache::Entry::dataSize, entries_, evictToFit(), grk::CompressedChunkCache::Entry::inMemory, mutex_, pushFrontLRU(), removeLRU(), and grk::CompressedChunkCache::Entry::seq.
|
inlineprivate |
Reload tile part data from disk into the existing TPFetch objects.
References codecFormat_, currentBytes_, grk::CompressedChunkCache::Entry::dataSize, diskCache_, grk::CompressedChunkCache::Entry::inMemory, grk::memStreamCreate(), and grk::CompressedChunkCache::Entry::seq.
Referenced by get().
|
inlineprivate |
|
inlinestaticprivate |
Resolve max bytes from environment or use provided value.
Checks GRK_CACHEMAX first, then GDAL_CACHEMAX.
References kDefaultMaxBytes.
Referenced by CompressedChunkCache().
|
inlineprivate |
Serialize tile part data to disk and release in-memory buffers.
Disk format: [uint16_t numParts] For each part: [uint64_t offset][uint64_t length] For each part: [length bytes of data]
References currentBytes_, grk::CompressedChunkCache::Entry::dataSize, diskCache_, grk::CompressedChunkCache::Entry::inMemory, and grk::CompressedChunkCache::Entry::seq.
Referenced by evictToFit().
|
private |
Referenced by CompressedChunkCache(), and reloadFromDisk().
|
private |
Referenced by clear(), CompressedChunkCache(), currentBytes(), evictToFit(), put(), reloadFromDisk(), and spillToDisk().
|
private |
Referenced by clear(), CompressedChunkCache(), reloadFromDisk(), and spillToDisk().
|
private |
Referenced by clear(), contains(), evictToFit(), get(), put(), and size().
|
staticconstexprprivate |
Referenced by resolveMaxBytes().
|
private |
Referenced by clear(), evictToFit(), promoteLRU(), pushFrontLRU(), and removeLRU().
|
private |
Referenced by clear(), evictToFit(), promoteLRU(), pushFrontLRU(), and removeLRU().
|
private |
Referenced by CompressedChunkCache(), evictToFit(), and maxBytes().
|
mutableprivate |
Referenced by clear(), contains(), currentBytes(), get(), put(), and size().