BuildCache
Public Member Functions | Private Member Functions | List of all members
bcache::local_cache_t Class Reference

Public Member Functions

 local_cache_t ()
 Initialize the cache object. More...
 
 ~local_cache_t ()
 De-initialzie the cache object.
 
void clear ()
 Clear all entries in the cache.
 
void show_stats ()
 Show cache statistics (print to standard out).
 
void zero_stats ()
 Clear the cache statistics.
 
void add_direct (const std::string &direct_hash, const direct_mode_manifest_t &manifest)
 Add a new direct mode entry to the cache. More...
 
direct_mode_manifest_t lookup_direct (const std::string &direct_hash)
 Check if a direct mode entry exists in the cache. More...
 
void add (const std::string &hash, const cache_entry_t &entry, const std::map< std::string, expected_file_t > &expected_files, const bool allow_hard_links)
 Add a set of files to the cache. More...
 
std::pair< cache_entry_t, file::file_lock_tlookup (const std::string &hash)
 Check if an entry exists in the cache. More...
 
void get_file (const std::string &hash, const std::string &source_id, const std::string &target_path, const bool is_compressed, const bool allow_hard_links)
 Copy a cached file to the local file system. More...
 
bool update_stats (const std::string &hash, const cache_stats_t &delta) const noexcept
 Update statistics associated with the given entry. More...
 

Private Member Functions

std::string hash_to_cache_entry_path (const std::string &hash) const
 
std::string get_cache_files_folder () const
 
void perform_housekeeping ()
 

Constructor & Destructor Documentation

◆ local_cache_t()

bcache::local_cache_t::local_cache_t ( )

Initialize the cache object.

Exceptions
runtime_errorif the cache could not be initialized.

Member Function Documentation

◆ add()

void bcache::local_cache_t::add ( const std::string &  hash,
const cache_entry_t entry,
const std::map< std::string, expected_file_t > &  expected_files,
const bool  allow_hard_links 
)

Add a set of files to the cache.

Parameters
hashThe cache entry identifier.
entryThe cache entry data (files, stdout, etc).
expected_filesPaths to the actual files in the local file system (map from file ID to an expected file descriptor).
allow_hard_linksWhether or not to allow hard links to be used when caching files.

◆ add_direct()

void bcache::local_cache_t::add_direct ( const std::string &  direct_hash,
const direct_mode_manifest_t manifest 
)

Add a new direct mode entry to the cache.

Parameters
direct_hashThe hash of the direct mode cache entry.
manifestThe direct mode manifest.

◆ get_file()

void bcache::local_cache_t::get_file ( const std::string &  hash,
const std::string &  source_id,
const std::string &  target_path,
const bool  is_compressed,
const bool  allow_hard_links 
)

Copy a cached file to the local file system.

Parameters
hashThe cache entry identifier.
source_idThe ID of the cached file to copy.
target_pathThe path to the local file.
is_compressedTrue if the cached data is compressed.
allow_hard_linksTrue if hard links are allowed.

◆ lookup()

std::pair< cache_entry_t, file::file_lock_t > bcache::local_cache_t::lookup ( const std::string &  hash)

Check if an entry exists in the cache.

Parameters
hashThe cache entry identifier.
Returns
A pair of a cache entry struct and a file lock object. If there was no cache hit, the entry will be empty, and the file lock object will not hold any lock.

◆ lookup_direct()

direct_mode_manifest_t bcache::local_cache_t::lookup_direct ( const std::string &  direct_hash)

Check if a direct mode entry exists in the cache.

Parameters
direct_hashThe hash of the direct mode cache entry.
Returns
A a direct mode manifest. If there was no cache hit the manifest will be empty.

◆ update_stats()

bool bcache::local_cache_t::update_stats ( const std::string &  hash,
const cache_stats_t delta 
) const
noexcept

Update statistics associated with the given entry.

Parameters
hashThe hash of the entry to which the stats belong.
deltaThe incremental stats delta.
Returns
true if the stats were successfully updated, otherwise false.
Note
The hash argument is only used for selecting where in the local cache structure to store the stats file.

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