Turi Create
4.0
|
#include <core/storage/fileio/fixed_size_cache_manager.hpp>
Public Member Functions | |
cache_id_type | get_temp_cache_id (std::string suffix="") |
std::shared_ptr< cache_block > | new_cache (cache_id_type cache_id) |
std::shared_ptr< cache_block > | get_cache (cache_id_type cache_id) |
void | free (std::shared_ptr< cache_block > block) |
void | clear () |
size_t | get_cache_utilization () |
A global singleton object managing the allocation/deallocation of cache blocks. The basic mechanism of operation is such:
The relevant constants are thus: FILEIO_MAXIMUM_CACHE_CAPACITY : the maximum total size of all cache blocks FILEIO_MAXIMUM_CACHE_CAPACITY_PER_FILE : the maximum size of each cache blocks FILEIO_INITIAL_CAPACITY_PER_FILE : the initial size of each cache blocks
We try our best to maintain cache utilization below the maximum. However, it is possible to exceed maximum cache utilization under certain race conditions since we avoid locking on the cache utilization counter.
Definition at line 179 of file fixed_size_cache_manager.hpp.
void turi::fileio::fixed_size_cache_manager::clear | ( | ) |
Clear all cache blocks in the manager. Reset to initial state.
void turi::fileio::fixed_size_cache_manager::free | ( | std::shared_ptr< cache_block > | block | ) |
Free the data in the cache block. Delete the allocated memory or temp file associated with the cache.
NOT thread safe to call on the same block.
std::shared_ptr<cache_block> turi::fileio::fixed_size_cache_manager::get_cache | ( | cache_id_type | cache_id | ) |
Returns the pointer to the cache_block assocaited with the cache_id, Throws std::out_of_range if the cache_id does not exist.
Thread safe.
|
inline |
Returns the amount of memory being used by the caches.
Definition at line 224 of file fixed_size_cache_manager.hpp.
cache_id_type turi::fileio::fixed_size_cache_manager::get_temp_cache_id | ( | std::string | suffix = "" | ) |
Returns a temporary cache id that is not yet used by the manager.
std::shared_ptr<cache_block> turi::fileio::fixed_size_cache_manager::new_cache | ( | cache_id_type | cache_id | ) |
Allocate a new cache block of up to some maximum capcity. If the cache_id already exists, the data will be lost.
Returns a pointer to the cache block. Thread safe.