Skip to content

Commit

Permalink
New memcached env vars were implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
AJIOB authored and sylvestre committed Feb 20, 2024
1 parent e845798 commit 9a00e7e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,9 @@ fn config_from_env() -> Result<EnvConfig> {
// ======= redis =======
let redis = if let Ok(url) = env::var("SCCACHE_REDIS") {
let ttl = number_from_env_var("SCCACHE_REDIS_EXPIRATION")
.or_else(|| number_from_env_var("SCCACHE_REDIS_TTL"));
let ttl = ttl.transpose()?.unwrap_or(DEFAULT_REDIS_CACHE_TTL);
.or_else(|| number_from_env_var("SCCACHE_REDIS_TTL"))
.transpose()?
.unwrap_or(DEFAULT_REDIS_CACHE_TTL);

let key_prefix = key_prefix_from_env_var("SCCACHE_REDIS_KEY_PREFIX");

Expand All @@ -652,21 +653,28 @@ fn config_from_env() -> Result<EnvConfig> {
None
};

if env::var_os("SCCACHE_REDIS_EXPIRATION").is_some()
&& env::var_os("SCCACHE_REDIS_TTL").is_some()
{
bail!("You mustn't set both SCCACHE_REDIS_EXPIRATION and SCCACHE_REDIS_TTL. Use only one.");
}

// ======= memcached =======
let expiration = match env::var("SCCACHE_MEMCACHED_EXPIRATION").ok() {
None => DEFAULT_MEMCACHED_CACHE_EXPIRATION,
Some(v) => v
.parse()
.map_err(|err| anyhow!("SCCACHE_MEMCACHED_EXPIRATION value is invalid: {err:?}"))?,
};
let memcached = if let Ok(url) = env::var("SCCACHE_MEMCACHED") {
let expiration = number_from_env_var("SCCACHE_MEMCACHED_EXPIRATION")
.transpose()?
.unwrap_or(DEFAULT_MEMCACHED_CACHE_EXPIRATION);

let memcached = env::var("SCCACHE_MEMCACHED")
.ok()
.map(|url| MemcachedCacheConfig {
let key_prefix = key_prefix_from_env_var("SCCACHE_MEMCACHED_KEY_PREFIX");

Some(MemcachedCacheConfig {
url,
expiration,
key_prefix: String::new(),
});
key_prefix,
})
} else {
None
};

// ======= GCP/GCS =======
if (env::var("SCCACHE_GCS_CREDENTIALS_URL").is_ok()
Expand Down

0 comments on commit 9a00e7e

Please sign in to comment.