Cachier 1.0
Fast C++ header only library that provides simple and efficient way to cache computed data for files
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
Cachier Class Reference

The Cachier class. More...

#include <cachier.h>

Classes

struct  HashResult
 The HashResult class. More...
 

Public Types

enum  CacheOverwriteOption { OVERWRITE_CACHE , DONT_OVERWRITE_CACHE }
 The CacheOverwriteOption enum.
 

Public Member Functions

 Cachier (const std::string &cache_store_path, bool ensure_cache_store_path=true)
 Cachier.
 
HashResult addCache (const std::string &filename, const std::string &content="", const CacheOverwriteOption &cache_overwrite_option=DONT_OVERWRITE_CACHE)
 addCache
 
bool cacheExists (const std::size_t &key)
 cacheExists
 
bool cacheExists (const std::string &filename)
 cacheExists
 
bool isInitialized ()
 isInitialized
 
HashResult computeHash (const std::string &filename)
 computeHash
 
std::string getContent (const std::string &key)
 getContent
 

Detailed Description

The Cachier class.

Author
Keshav Bhatt kesha.nosp@m.vnrj.nosp@m.@gmai.nosp@m.l.co.nosp@m.m

Constructor & Destructor Documentation

◆ Cachier()

Cachier::Cachier ( const std::string &  cache_store_path,
bool  ensure_cache_store_path = true 
)
inline

Cachier.

Instantiate Cachier object using provided cache store path.

Parameters
cache_store_pathThe directory path where cache will be stored.
ensure_cache_store_pathTry to create cache store path during cachier object instantiation, default true.

Member Function Documentation

◆ addCache()

HashResult Cachier::addCache ( const std::string &  filename,
const std::string &  content = "",
const CacheOverwriteOption cache_overwrite_option = DONT_OVERWRITE_CACHE 
)
inline

addCache

Compute HashResult for file and create a cache entry with given content in cache_store_path.

Parameters
filenameThe complete file path to which the cache needs to be added.
contentOptional content or computed data to store in the cache file.
cache_overwrite_optionCacheOverwriteOption option whether overwrite content if cache entry already exists, Default is CacheOverwriteOption::DONT_OVERWRITE_CACHE
Returns
The computed HashResult object.

◆ cacheExists() [1/2]

bool Cachier::cacheExists ( const std::size_t &  key)
inline

cacheExists

Return whether cache exists for the given hash key.

Parameters
Thehash key for cache entry.
Returns
True if cache exists for provided key, false otherwise.

◆ cacheExists() [2/2]

bool Cachier::cacheExists ( const std::string &  filename)
inline

cacheExists

Retunrs whether cache exists for the given filename. Computes hash using file data and look for a file entry in cache_store_path, return true if cache entry found indicating file is cached, otherwise false.

Parameters
filenameThe filename for which cache presense is being checked.
Returns
True if file exists in cache store path.

◆ computeHash()

HashResult Cachier::computeHash ( const std::string &  filename)
inline

computeHash

Return a HashResult object containing computed hash from file data and error if any, The hash is computed using these file stats:

  • File name
  • File size
  • Last modification time
  • First 8 bytes of file aka. file header info.
Parameters
filenameThe File path for which the hash to be computed.
Returns
The computed HashResult object.

◆ getContent()

std::string Cachier::getContent ( const std::string &  key)
inline

getContent

Returns data stored in cache for provided key.

Parameters
keyThe hash key to use to get content.
Returns
The content string stored with key.

◆ isInitialized()

bool Cachier::isInitialized ( )
inline

isInitialized

Returns the state of library initialization.

Returns
True if initialized, false otherwise.

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