BuildCache
redis_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_REDIS_CACHE_PROVIDER_HPP_
21 #define BUILDCACHE_REDIS_CACHE_PROVIDER_HPP_
22 
23 #include <cache/remote_cache_provider.hpp>
24 
25 // Forward declaration.
26 typedef struct redisContext redisContext;
27 
28 namespace bcache {
29 
31 public:
33  ~redis_cache_provider_t() override;
34 
35  // Implementation of the remote_cache_provider_t interface.
36  bool connect(const std::string& host_description) override;
37  bool is_connected() const override;
38  cache_entry_t lookup(const std::string& hash) override;
39  void add(const std::string& hash,
40  const cache_entry_t& entry,
41  const std::map<std::string, expected_file_t>& expected_files) override;
42  void get_file(const std::string& hash,
43  const std::string& source_id,
44  const std::string& target_path,
45  const bool is_compressed) override;
46 
47 private:
49  void disconnect();
50 
56  std::string get_data(const std::string& key);
57 
63  void set_data(const std::string& key, const std::string& data);
64 
65  redisContext* m_ctx = nullptr;
66 };
67 
68 } // namespace bcache
69 
70 #endif // BUILDCACHE_REDIS_CACHE_PROVIDER_HPP_
bcache::redis_cache_provider_t::lookup
cache_entry_t lookup(const std::string &hash) override
Check if an entry exists in the cache.
Definition: redis_cache_provider.cpp:124
bcache::remote_cache_provider_t
Definition: remote_cache_provider.hpp:31
bcache::redis_cache_provider_t
Definition: redis_cache_provider.hpp:30
bcache
The top level namespace.
Definition: compressor.cpp:34
bcache::redis_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: redis_cache_provider.cpp:215
bcache::redis_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: redis_cache_provider.cpp:136
bcache::redis_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: redis_cache_provider.cpp:162
bcache::redis_cache_provider_t::disconnect
void disconnect()
Disconnect (usually as a result of an error).
Definition: redis_cache_provider.cpp:117
bcache::redis_cache_provider_t::connect
bool connect(const std::string &host_description) override
Connect to the remote cache.
Definition: redis_cache_provider.cpp:73
bcache::redis_cache_provider_t::is_connected
bool is_connected() const override
Check if we have a connection to the remote cache.
Definition: redis_cache_provider.cpp:113
bcache::redis_cache_provider_t::get_data
std::string get_data(const std::string &key)
Get a binary data blob from the remote cache.
Definition: redis_cache_provider.cpp:174
bcache::cache_entry_t
Meta data for a single cache entry.
Definition: cache_entry.hpp:28