.. _program_listing_file_include_client_cache.hpp: Program Listing for File cache.hpp ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/client/cache.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* Copyright 2018-2025, Barcelona Supercomputing Center (BSC), Spain Copyright 2015-2025, Johannes Gutenberg Universitaet Mainz, Germany This software was partially supported by the EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). This software was partially supported by the ADA-FS project under the SPPEXA project funded by the DFG. This software was partially supported by the the European Union’s Horizon 2020 JTI-EuroHPC research and innovation programme, by the project ADMIRE (Project ID: 956748, admire-eurohpc.eu) This project was partially promoted by the Ministry for Digital Transformation and the Civil Service, within the framework of the Recovery, Transformation and Resilience Plan - Funded by the European Union -NextGenerationEU. This file is part of GekkoFS' POSIX interface. GekkoFS' POSIX interface is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. GekkoFS' POSIX interface is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with GekkoFS' POSIX interface. If not, see . SPDX-License-Identifier: LGPL-3.0-or-later */ #ifndef GKFS_CLIENT_CACHE #define GKFS_CLIENT_CACHE #include #include #include #include #include #include #include #include #include namespace gkfs::cache { namespace dir { struct cache_entry { gkfs::filemap::FileType file_type; uint64_t size; time_t ctime; }; class DentryCache { private: // >: Associate a directory id with its entries // containing the directory name and cache entry metadata std::unordered_map> entries_; // : Associate a directory path with a unique id std::unordered_map entry_dir_id_; std::mutex mtx_; // Mutex to protect the cache std::hash str_hash; // hash to generate ids uint32_t gen_dir_id(const std::string& dir_path); uint32_t get_dir_id(const std::string& dir_path); public: DentryCache() = default; virtual ~DentryCache() = default; void insert(const std::string& parent_dir, std::string name, cache_entry value); std::optional get(const std::string& parent_dir, const std::string& name); void clear_dir(const std::string& dir_path); void dump_cache_to_log(const std::string& dir_path); void clear(); }; } // namespace dir namespace file { class WriteSizeCache { private: // > std::unordered_map> size_cache; std::mutex mtx_; // Flush threshold in number of write ops per file size_t flush_threshold_{0}; public: WriteSizeCache() = default; virtual ~WriteSizeCache() = default; std::pair record(std::string path, size_t size); std::pair reset(const std::string& path, bool evict); std::pair flush(const std::string& path, bool evict = true); // GETTER/SETTER size_t flush_threshold() const; void flush_threshold(size_t flush_threshold); }; } // namespace file } // namespace gkfs::cache #endif // GKFS_CLIENT_CACHE