diff --git a/doc/configuration.md b/doc/configuration.md index 3a7ae62..48f7354 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -27,6 +27,7 @@ The following options control the behavior of BuildCache: | `BUILDCACHE_PERF` | `perf` | Enable performance logging | false | | `BUILDCACHE_PREFIX` | `prefix` | Prefix command for cache misses | None | | `BUILDCACHE_READ_ONLY` | `read_only` | Only read and use the cache without updating it | false | +| `BUILDCACHE_READ_ONLY_REMOTE` | `read_only_remote` | Only read and use the remote cache without updating it (implied by `BUILDCACHE_READ_ONLY`) | false | | `BUILDCACHE_REMOTE` | `remote` | Address of remote cache server (`protocol://host:port/path`, where `protocol` can be `redis` or `s3`, and `port` and `path` are optional) | None | | `BUILDCACHE_REMOTE_LOCKS` | `remote_locks` | Use a (potentially slower) file locking mechanism that is safe if the local cache is on a fileshare | false | | `BUILDCACHE_S3_ACCESS` | `s3_access` | S3 access key | None | diff --git a/src/cache/cache.cpp b/src/cache/cache.cpp index 25b3c90..0afac67 100644 --- a/src/cache/cache.cpp +++ b/src/cache/cache.cpp @@ -99,7 +99,7 @@ void cache_t::add(const hasher_t::hash_t hash, } // Add the entry to the remote cache. - if (m_remote_cache.is_connected()) { + if (m_remote_cache.is_connected() && !config::read_only_remote()) { const auto max_remote_size = config::max_remote_entry_size(); if (size < max_remote_size || max_remote_size <= 0) { // Note: We always compress entries for the remote cache. diff --git a/src/config/configuration.cpp b/src/config/configuration.cpp index ccbe083..716d719 100644 --- a/src/config/configuration.cpp +++ b/src/config/configuration.cpp @@ -67,6 +67,7 @@ int64_t s_max_remote_entry_size = DEFAULT_MAX_REMOTE_ENTRY_SIZE; bool s_perf = false; std::string s_prefix; bool s_read_only = false; +bool s_read_only_remote = false; bool s_remote_locks = false; std::string s_remote; std::string s_s3_access; @@ -269,6 +270,13 @@ void load_from_file(const std::string& file_name) { } } + { + const auto* node = cJSON_GetObjectItemCaseSensitive(root, "read_only_remote"); + if (cJSON_IsBool(node)) { + s_read_only_remote = cJSON_IsTrue(node); + } + } + { const auto* node = cJSON_GetObjectItemCaseSensitive(root, "remote"); if (cJSON_IsString(node) && node->valuestring != nullptr) { @@ -485,6 +493,13 @@ void init() { } } + { + const env_var_t env("BUILDCACHE_READ_ONLY_REMOTE"); + if (env) { + s_read_only_remote = env.as_bool(); + } + } + { const env_var_t env("BUILDCACHE_REMOTE"); if (env) { @@ -599,6 +614,10 @@ bool read_only() { return s_read_only; } +bool read_only_remote() { + return s_read_only_remote; +} + const std::string& remote() { return s_remote; } diff --git a/src/config/configuration.hpp b/src/config/configuration.hpp index d6ebf40..72d1470 100644 --- a/src/config/configuration.hpp +++ b/src/config/configuration.hpp @@ -114,6 +114,9 @@ const std::string& prefix(); /// @returns true if the readonly mode is enabled. bool read_only(); +/// @returns true if the remote cache is read only. +bool read_only_remote(); + /// @returns the remote cache service address. const std::string& remote(); diff --git a/src/main.cpp b/src/main.cpp index cf9ca7f..16f37e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -199,6 +199,8 @@ std::unique_ptr find_suitable_wrapper( std::cout << " BUILDCACHE_PREFIX: " << bcache::config::prefix() << "\n"; std::cout << " BUILDCACHE_READ_ONLY: " << (bcache::config::read_only() ? "true" : "false") << "\n"; + std::cout << " BUILDCACHE_READ_ONLY_REMOTE: " + << (bcache::config::read_only_remote() ? "true" : "false") << "\n"; std::cout << " BUILDCACHE_REMOTE: " << bcache::config::remote() << "\n"; std::cout << " BUILDCACHE_REMOTE_LOCKS: " << (bcache::config::remote_locks() ? "true" : "false") << "\n";