6 #ifndef FILEIO_FIXED_SIZE_CACHE_MANAGER_HPP 7 #define FILEIO_FIXED_SIZE_CACHE_MANAGER_HPP 11 #include <core/parallel/pthread_tools.hpp> 12 #include <unordered_map> 13 #include <core/parallel/atomic.hpp> 14 #include <core/storage/fileio/temp_files.hpp> 15 #include <core/storage/fileio/general_fstream_sink.hpp> 16 #include <core/storage/fileio/fileio_constants.hpp> 22 class fixed_size_cache_manager;
24 typedef std::string cache_id_type;
37 cache_block(cache_id_type cache_id,
size_t max_capacity,
52 inline cache_id_type get_cache_id()
const {
return cache_id; }
57 inline bool is_pointer()
const {
return filename.empty(); }
62 inline bool is_file()
const {
return !filename.empty(); }
82 inline const std::string&
get_filename()
const {
return filename; }
89 std::streamsize bufsize) {
90 if (data == NULL)
return false;
94 memcpy(data + size, c, bufsize);
107 std::shared_ptr<fileio_impl::general_fstream_sink>
write_to_file();
116 cache_id_type cache_id = 0;
118 size_t maximum_capacity = 0;
126 std::string filename;
133 void initialize_memory(
size_t max_capacity);
137 void release_memory();
183 static std::shared_ptr<const fixed_size_cache_manager> hold_instance();
189 cache_id_type get_temp_cache_id(std::string suffix =
"");
198 std::shared_ptr<cache_block> new_cache(cache_id_type cache_id);
206 std::shared_ptr<cache_block> get_cache(cache_id_type cache_id);
214 void free(std::shared_ptr<cache_block> block);
225 return current_cache_utilization.value;
241 size_t temp_cache_counter = 0;
243 atomic<size_t> current_cache_utilization;
246 std::unordered_map<std::string, std::shared_ptr<cache_block> > cache_blocks;
251 void increment_utilization(ssize_t increment);
255 void decrement_utilization(ssize_t decrement);
261 void try_cache_evict();
const std::string & get_filename() const
const size_t get_pointer_capacity() const
bool write_bytes_to_memory_cache(const char *c, std::streamsize bufsize)
const size_t get_pointer_size() const
size_t get_cache_utilization()
char * get_pointer() const
bool extend_capacity(size_t new_capacity)
std::shared_ptr< fileio_impl::general_fstream_sink > write_to_file()