Grok 20.3.2
grk::DiskCache Class Reference

Secondary disk-based cache for compressed tile data. More...

#include <DiskCache.h>

Public Member Functions

 DiskCache (const std::string &basePath="")
 Create a disk cache in a temporary directory.
 ~DiskCache ()
 DiskCache (const DiskCache &)=delete
DiskCacheoperator= (const DiskCache &)=delete
void store (uint16_t tileIndex, const uint8_t *data, size_t size)
 Store raw bytes to disk for a given tile.
std::optional< std::vector< uint8_t > > load (uint16_t tileIndex)
 Load raw bytes from disk for a given tile.
bool contains (uint16_t tileIndex) const
 Check if a tile is stored on disk.
void clear ()
 Remove all cached entries from disk.
size_t size () const

Private Member Functions

std::filesystem::path tilePath (uint16_t tileIndex) const

Private Attributes

std::filesystem::path cacheDir_
std::unordered_map< uint16_t, size_t > index_
std::mutex mutex_

Detailed Description

Secondary disk-based cache for compressed tile data.

When the in-memory CompressedChunkCache evicts an entry, it is spilled here. The disk cache stores each tile's raw byte blob in a separate file under a temporary directory.

Reads use standard file I/O. The directory is cleaned up on destruction.

Constructor & Destructor Documentation

◆ DiskCache() [1/2]

grk::DiskCache::DiskCache ( const std::string & basePath = "")
inlineexplicit

Create a disk cache in a temporary directory.

Parameters
basePathoptional base directory (default: system temp)

References cacheDir_.

Referenced by DiskCache(), and operator=().

◆ ~DiskCache()

grk::DiskCache::~DiskCache ( )
inline

References cacheDir_.

◆ DiskCache() [2/2]

grk::DiskCache::DiskCache ( const DiskCache & )
delete

References DiskCache().

Member Function Documentation

◆ clear()

void grk::DiskCache::clear ( )
inline

Remove all cached entries from disk.

References index_, mutex_, and tilePath().

◆ contains()

bool grk::DiskCache::contains ( uint16_t tileIndex) const
inline

Check if a tile is stored on disk.

References index_, and mutex_.

◆ load()

std::optional< std::vector< uint8_t > > grk::DiskCache::load ( uint16_t tileIndex)
inline

Load raw bytes from disk for a given tile.

Returns
the bytes if found, or std::nullopt

References index_, mutex_, and tilePath().

◆ operator=()

DiskCache & grk::DiskCache::operator= ( const DiskCache & )
delete

References DiskCache().

◆ size()

size_t grk::DiskCache::size ( ) const
inline

References index_, and mutex_.

Referenced by store().

◆ store()

void grk::DiskCache::store ( uint16_t tileIndex,
const uint8_t * data,
size_t size )
inline

Store raw bytes to disk for a given tile.

References index_, mutex_, size(), and tilePath().

◆ tilePath()

std::filesystem::path grk::DiskCache::tilePath ( uint16_t tileIndex) const
inlineprivate

References cacheDir_.

Referenced by clear(), load(), and store().

Member Data Documentation

◆ cacheDir_

std::filesystem::path grk::DiskCache::cacheDir_
private

Referenced by DiskCache(), tilePath(), and ~DiskCache().

◆ index_

std::unordered_map<uint16_t, size_t> grk::DiskCache::index_
private

Referenced by clear(), contains(), load(), size(), and store().

◆ mutex_

std::mutex grk::DiskCache::mutex_
mutableprivate

Referenced by clear(), contains(), load(), size(), and store().


The documentation for this class was generated from the following file: