BuildCache
http_cache_provider.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_HTTP_CACHE_PROVIDER_HPP_
21 #define BUILDCACHE_HTTP_CACHE_PROVIDER_HPP_
22 
23 #include <cache/remote_cache_provider.hpp>
24 
25 namespace bcache {
26 
28 public:
30  ~http_cache_provider_t() override;
31 
32  // Implementation of the remote_cache_provider_t interface.
33  bool connect(const std::string& host_description) override;
34  bool is_connected() const override;
35  cache_entry_t lookup(const std::string& hash) override;
36  void add(const std::string& hash,
37  const cache_entry_t& entry,
38  const std::map<std::string, expected_file_t>& expected_files) override;
39  void get_file(const std::string& hash,
40  const std::string& source_id,
41  const std::string& target_path,
42  const bool is_compressed) override;
43 
44 protected:
47  std::string get_path() const;
48 
49 private:
54  virtual std::vector<std::string> get_header(const std::string& method,
55  const std::string& key) const;
56 
58  void disconnect();
59 
63  std::string get_object_url(const std::string& key);
64 
70  std::string get_data(const std::string& key);
71 
77  void set_data(const std::string& key, const std::string& data);
78 
79  std::string m_host;
80  std::string m_path;
81  int m_port;
82 
83  bool m_ready_for_action = false;
84 };
85 
86 } // namespace bcache
87 
88 #endif // BUILDCACHE_S3_CACHE_PROVIDER_HPP_
bcache::http_cache_provider_t::connect
bool connect(const std::string &host_description) override
Connect to the remote cache.
Definition: http_cache_provider.cpp:60
bcache::http_cache_provider_t::get_header
virtual std::vector< std::string > get_header(const std::string &method, const std::string &key) const
Get the headers for the HTTP request.
Definition: http_cache_provider.cpp:148
bcache::http_cache_provider_t
Definition: http_cache_provider.hpp:27
bcache::http_cache_provider_t::get_file
void get_file(const std::string &hash, const std::string &source_id, const std::string &target_path, const bool is_compressed) override
Copy a cached file to the local file system.
Definition: http_cache_provider.cpp:132
bcache::http_cache_provider_t::get_data
std::string get_data(const std::string &key)
Get a binary data blob from the remote cache.
Definition: http_cache_provider.cpp:154
bcache::http_cache_provider_t::is_connected
bool is_connected() const override
Check if we have a connection to the remote cache.
Definition: http_cache_provider.cpp:80
bcache::http_cache_provider_t::lookup
cache_entry_t lookup(const std::string &hash) override
Check if an entry exists in the cache.
Definition: http_cache_provider.cpp:94
bcache::remote_cache_provider_t
Definition: remote_cache_provider.hpp:31
bcache
The top level namespace.
Definition: compressor.cpp:34
bcache::http_cache_provider_t::disconnect
void disconnect()
Disconnect (usually as a result of an error).
Definition: http_cache_provider.cpp:84
bcache::http_cache_provider_t::add
void add(const std::string &hash, const cache_entry_t &entry, const std::map< std::string, expected_file_t > &expected_files) override
Adds a set of files to the cache.
Definition: http_cache_provider.cpp:106
bcache::http_cache_provider_t::get_path
std::string get_path() const
Get the path of the destination URL.
Definition: http_cache_provider.cpp:144
bcache::http_cache_provider_t::get_object_url
std::string get_object_url(const std::string &key)
Get the full URL for a given object.
Definition: http_cache_provider.cpp:88
bcache::http_cache_provider_t::set_data
void set_data(const std::string &key, const std::string &data)
Set a binary data blob in the remote cache.
Definition: http_cache_provider.cpp:188
bcache::cache_entry_t
Meta data for a single cache entry.
Definition: cache_entry.hpp:28