Make the TTL for disk cache configurable, we can now completely disable
disk cache lookup for example by doing: nix copy --from <binary-cahe> <store-path> --option \ positive-disk-cache-ttl 0 Issues: #1885 #2035
This commit is contained in:
parent
27e9ce0eb2
commit
2855c3d965
2 changed files with 11 additions and 8 deletions
|
@ -310,6 +310,12 @@ public:
|
||||||
"Disabled substituters that may be enabled via the substituters option by untrusted users.",
|
"Disabled substituters that may be enabled via the substituters option by untrusted users.",
|
||||||
{"trusted-binary-caches"}};
|
{"trusted-binary-caches"}};
|
||||||
|
|
||||||
|
Setting<int> ttlNegativeDiskCache{this, 3600, "negative-disk-cache-ttl",
|
||||||
|
"The TTL in seconds for negative lookups in the disk cache."};
|
||||||
|
|
||||||
|
Setting<int> ttlPositiveDiskCache{this, 30 * 24 * 3600, "positive-disk-cache-ttl",
|
||||||
|
"The TTL in seconds for positive lookups in the disk cache."};
|
||||||
|
|
||||||
Setting<Strings> trustedUsers{this, {"root"}, "trusted-users",
|
Setting<Strings> trustedUsers{this, {"root"}, "trusted-users",
|
||||||
"Which users or groups are trusted to ask the daemon to do unsafe things."};
|
"Which users or groups are trusted to ask the daemon to do unsafe things."};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "nar-info-disk-cache.hh"
|
#include "nar-info-disk-cache.hh"
|
||||||
#include "sync.hh"
|
#include "sync.hh"
|
||||||
#include "sqlite.hh"
|
#include "sqlite.hh"
|
||||||
|
#include "globals.hh"
|
||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
|
@ -47,10 +48,6 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache
|
||||||
{
|
{
|
||||||
public:
|
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. */
|
/* How often to purge expired entries from the cache. */
|
||||||
const int purgeInterval = 24 * 3600;
|
const int purgeInterval = 24 * 3600;
|
||||||
|
|
||||||
|
@ -116,8 +113,8 @@ public:
|
||||||
SQLiteStmt(state->db,
|
SQLiteStmt(state->db,
|
||||||
"delete from NARs where ((present = 0 and timestamp < ?) or (present = 1 and timestamp < ?))")
|
"delete from NARs where ((present = 0 and timestamp < ?) or (present = 1 and timestamp < ?))")
|
||||||
.use()
|
.use()
|
||||||
(now - ttlNegative)
|
(now - settings.ttlNegativeDiskCache)
|
||||||
(now - ttlPositive)
|
(now - settings.ttlPositiveDiskCache)
|
||||||
.exec();
|
.exec();
|
||||||
|
|
||||||
debug("deleted %d entries from the NAR info disk cache", sqlite3_changes(state->db));
|
debug("deleted %d entries from the NAR info disk cache", sqlite3_changes(state->db));
|
||||||
|
@ -186,8 +183,8 @@ public:
|
||||||
auto queryNAR(state->queryNAR.use()
|
auto queryNAR(state->queryNAR.use()
|
||||||
(cache.id)
|
(cache.id)
|
||||||
(hashPart)
|
(hashPart)
|
||||||
(now - ttlNegative)
|
(now - settings.ttlNegativeDiskCache)
|
||||||
(now - ttlPositive));
|
(now - settings.ttlPositiveDiskCache));
|
||||||
|
|
||||||
if (!queryNAR.next())
|
if (!queryNAR.next())
|
||||||
return {oUnknown, 0};
|
return {oUnknown, 0};
|
||||||
|
|
Loading…
Reference in a new issue