diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index 117404ec1..36c8b7357 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -310,6 +310,12 @@ public: "Disabled substituters that may be enabled via the substituters option by untrusted users.", {"trusted-binary-caches"}}; + Setting ttlNegativeDiskCache{this, 3600, "negative-disk-cache-ttl", + "The TTL in seconds for negative lookups in the disk cache."}; + + Setting ttlPositiveDiskCache{this, 30 * 24 * 3600, "positive-disk-cache-ttl", + "The TTL in seconds for positive lookups in the disk cache."}; + Setting trustedUsers{this, {"root"}, "trusted-users", "Which users or groups are trusted to ask the daemon to do unsafe things."}; diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index 3c52303f0..1e143736f 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -1,6 +1,7 @@ #include "nar-info-disk-cache.hh" #include "sync.hh" #include "sqlite.hh" +#include "globals.hh" #include @@ -47,10 +48,6 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache { public: - /* How long negative and positive lookups are valid. */ - const int ttlNegative = 3600; - const int ttlPositive = 30 * 24 * 3600; - /* How often to purge expired entries from the cache. */ const int purgeInterval = 24 * 3600; @@ -116,8 +113,8 @@ public: SQLiteStmt(state->db, "delete from NARs where ((present = 0 and timestamp < ?) or (present = 1 and timestamp < ?))") .use() - (now - ttlNegative) - (now - ttlPositive) + (now - settings.ttlNegativeDiskCache) + (now - settings.ttlPositiveDiskCache) .exec(); debug("deleted %d entries from the NAR info disk cache", sqlite3_changes(state->db)); @@ -186,8 +183,8 @@ public: auto queryNAR(state->queryNAR.use() (cache.id) (hashPart) - (now - ttlNegative) - (now - ttlPositive)); + (now - settings.ttlNegativeDiskCache) + (now - settings.ttlPositiveDiskCache)); if (!queryNAR.next()) return {oUnknown, 0};