TINC
Toolkit for Interactive Computation
tinc::CacheManager Class Reference

The CacheManager class is in charge of data caching and cache metadata. More...

#include <CacheManager.hpp>

Public Member Functions

 CacheManager (DistributedPath cachePath=DistributedPath("tinc_cache.json"))
 
void appendEntry (CacheEntry &entry)
 append cache entry More...
 
std::vector< CacheEntryentries (size_t count=0)
 Get all in memory entries. More...
 
std::vector< std::string > findCache (const SourceInfo &sourceInfo, bool validateFile=true)
 Find files for SourceInfo. More...
 
void clearCache ()
 Clear all cached files, and cache information. More...
 
std::string cacheDirectory ()
 Get full cache path. More...
 
DistributedPath getDistributedPath ()
 Get current DistributedPath. More...
 
void updateFromDisk ()
 Read and validate cache file from disk. More...
 
void writeToDisk ()
 Write the current in memory cache to disk. More...
 
std::string dump ()
 Read cache metadata. More...
 

Static Public Member Functions

static int32_t computeCrc32 (std::string filename)
 compute CRC32 for file More...
 

Static Protected Member Functions

static void tincSchemaFormatChecker (const std::string &format, const std::string &value)
 

Protected Attributes

DistributedPath mCachePath
 
std::mutex mCacheLock
 
std::vector< CacheEntrymEntries
 
nlohmann::json_schema::json_validator mValidator
 

Detailed Description

The CacheManager class is in charge of data caching and cache metadata.

This class copies and renames files into the cache directory, keeping a metadata json file tracking the source of the data including information on how it was produced. The metadata follows the json schema defined in tinc/doc/tinc_cache_schema.json

Definition at line 116 of file CacheManager.hpp.

Constructor & Destructor Documentation

◆ CacheManager()

tinc::CacheManager::CacheManager ( DistributedPath  cachePath = DistributedPath("tinc_cache.json"))

Member Function Documentation

◆ appendEntry()

void tinc::CacheManager::appendEntry ( CacheEntry entry)

append cache entry

Parameters
theCacheEntry entry

◆ cacheDirectory()

std::string tinc::CacheManager::cacheDirectory ( )

Get full cache path.

◆ clearCache()

void tinc::CacheManager::clearCache ( )

Clear all cached files, and cache information.

Although this function will only delete files listed in the cache file, it should be used with caution.

◆ computeCrc32()

static int32_t tinc::CacheManager::computeCrc32 ( std::string  filename)
static

compute CRC32 for file

Parameters
filename
Returns
the CRC

◆ dump()

std::string tinc::CacheManager::dump ( )

Read cache metadata.

Returns
the json metadata as a string

◆ entries()

std::vector<CacheEntry> tinc::CacheManager::entries ( size_t  count = 0)

Get all in memory entries.

Parameters
countNumber of most recent entries to get
Returns
vector of CacheEntry objects

If count is 0, or greater than the number of entries, all the entries are returned.

◆ findCache()

std::vector<std::string> tinc::CacheManager::findCache ( const SourceInfo sourceInfo,
bool  validateFile = true 
)

Find files for SourceInfo.

Parameters
sourceInfodetails for files to find
validateFilevalidate file details against details in sourceInfo

◆ getDistributedPath()

DistributedPath tinc::CacheManager::getDistributedPath ( )

Get current DistributedPath.

◆ tincSchemaFormatChecker()

static void tinc::CacheManager::tincSchemaFormatChecker ( const std::string &  format,
const std::string &  value 
)
staticprotected

◆ updateFromDisk()

void tinc::CacheManager::updateFromDisk ( )

Read and validate cache file from disk.

This replaces the current in memory cache, so make sure you call writeToDisk() first if you want to store in memory cache.

◆ writeToDisk()

void tinc::CacheManager::writeToDisk ( )

Write the current in memory cache to disk.

This will overwrite the cache metadata file on disk

Member Data Documentation

◆ mCacheLock

std::mutex tinc::CacheManager::mCacheLock
protected

Definition at line 195 of file CacheManager.hpp.

◆ mCachePath

DistributedPath tinc::CacheManager::mCachePath
protected

Definition at line 194 of file CacheManager.hpp.

◆ mEntries

std::vector<CacheEntry> tinc::CacheManager::mEntries
protected

Definition at line 198 of file CacheManager.hpp.

◆ mValidator

nlohmann::json_schema::json_validator tinc::CacheManager::mValidator
protected
Initial value:
{nullptr,
static void tincSchemaFormatChecker(const std::string &format, const std::string &value)

Definition at line 204 of file CacheManager.hpp.


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