BuildCache
cache.hpp
1 //--------------------------------------------------------------------------------------------------
2 // Copyright (c) 2019 Marcus Geelnard
3 //
4 // This software is provided 'as-is', without any express or implied warranty. In no event will the
5 // authors be held liable for any damages arising from the use of this software.
6 //
7 // Permission is granted to anyone to use this software for any purpose, including commercial
8 // applications, and to alter it and redistribute it freely, subject to the following restrictions:
9 //
10 // 1. The origin of this software must not be misrepresented; you must not claim that you wrote
11 // the original software. If you use this software in a product, an acknowledgment in the
12 // product documentation would be appreciated but is not required.
13 //
14 // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
15 // being the original software.
16 //
17 // 3. This notice may not be removed or altered from any source distribution.
18 //--------------------------------------------------------------------------------------------------
19 
20 #ifndef BUILDCACHE_CACHE_HPP_
21 #define BUILDCACHE_CACHE_HPP_
22 
23 #include <base/string_list.hpp>
24 #include <cache/cache_entry.hpp>
25 #include <cache/expected_file.hpp>
26 #include <cache/local_cache.hpp>
27 #include <cache/remote_cache.hpp>
28 
29 #include <map>
30 #include <string>
31 
32 namespace bcache {
34 class cache_t {
35 public:
44  bool lookup_direct(const std::string& direct_hash,
45  const std::map<std::string, expected_file_t>& expected_files,
46  const bool allow_hard_links,
47  const bool create_target_dirs,
48  int& return_code) noexcept;
49 
54  void add_direct(const std::string& direct_hash,
55  const std::string& hash,
56  const string_list_t& implicit_input_files);
57 
66  bool lookup(const std::string& hash,
67  const std::map<std::string, expected_file_t>& expected_files,
68  const bool allow_hard_links,
69  const bool create_target_dirs,
70  int& return_code) noexcept;
71 
78  void add(const std::string& hash,
79  const cache_entry_t& entry,
80  const std::map<std::string, expected_file_t>& expected_files,
81  const bool allow_hard_links);
82 
83 private:
84  bool lookup_in_local_cache(const std::string& hash,
85  const std::map<std::string, expected_file_t>& expected_files,
86  const bool allow_hard_links,
87  const bool create_target_dirs,
88  int& return_code);
89 
90  bool lookup_in_remote_cache(const std::string& hash,
91  const std::map<std::string, expected_file_t>& expected_files,
92  const bool allow_hard_links,
93  const bool create_target_dirs,
94  int& return_code);
95 
96  local_cache_t m_local_cache;
97  remote_cache_t m_remote_cache;
98 };
99 } // namespace bcache
100 
101 #endif // BUILDCACHE_CACHE_HPP_
bcache::cache_t::lookup
bool lookup(const std::string &hash, const std::map< std::string, expected_file_t > &expected_files, const bool allow_hard_links, const bool create_target_dirs, int &return_code) noexcept
Perform a cache lookup.
Definition: cache.cpp:114
bcache
The top level namespace.
Definition: compressor.cpp:34
bcache::cache_t::add
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 new entry to the cache(s).
Definition: cache.cpp:147
bcache::cache_t::add_direct
void add_direct(const std::string &direct_hash, const std::string &hash, const string_list_t &implicit_input_files)
Add a new direct mode entry to the cache.
Definition: cache.cpp:88
bcache::string_list_t
A convenient vector of strings container with support functions for program argument handling.
Definition: string_list.hpp:30
bcache::local_cache_t
Definition: local_cache.hpp:36
bcache::cache_t
An interface to the different caches.
Definition: cache.hpp:34
bcache::remote_cache_t
Definition: remote_cache.hpp:31
bcache::cache_t::lookup_direct
bool lookup_direct(const std::string &direct_hash, const std::map< std::string, expected_file_t > &expected_files, const bool allow_hard_links, const bool create_target_dirs, int &return_code) noexcept
Perform a direct mode cache lookup.
Definition: cache.cpp:53
bcache::cache_entry_t
Meta data for a single cache entry.
Definition: cache_entry.hpp:28