forked from lix-project/lix
Merge pull request #2036 from AmineChikhaoui/disk-cache-ttl
Make the TTL for disk cache configurable
This commit is contained in:
commit
e10a7ec7eb
|
@ -456,6 +456,36 @@ builtins.fetchurl {
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-narinfo-cache-negative-ttl"><term><literal>narinfo-cache-negative-ttl</literal></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
|
||||||
|
<para>The TTL in seconds for negative lookups. If a store path is
|
||||||
|
queried from a substituter but was not found, there will be a
|
||||||
|
negative lookup cached in the local disk cache database for the
|
||||||
|
specified duration.</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry xml:id="conf-narinfo-cache-positive-ttl"><term><literal>narinfo-cache-positive-ttl</literal></term>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
|
||||||
|
<para>The TTL in seconds for positive lookups. If a store path is
|
||||||
|
queried from a substituter, the result of the query will be cached
|
||||||
|
in the local disk cache database including some of the NAR
|
||||||
|
metadata. The default TTL is a month, setting a shorter TTL for
|
||||||
|
positive lookups can be useful for binary caches that have
|
||||||
|
frequent garbage collection, in which case having a more frequent
|
||||||
|
cache invalidation would prevent trying to pull the path again and
|
||||||
|
failing with a hash mismatch if the build isn't reproducible.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
</listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry xml:id="conf-netrc-file"><term><literal>netrc-file</literal></term>
|
<varlistentry xml:id="conf-netrc-file"><term><literal>netrc-file</literal></term>
|
||||||
|
|
||||||
|
@ -511,7 +541,6 @@ password <replaceable>my-password</replaceable>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry xml:id="conf-pre-build-hook"><term><literal>pre-build-hook</literal></term>
|
<varlistentry xml:id="conf-pre-build-hook"><term><literal>pre-build-hook</literal></term>
|
||||||
|
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -788,7 +817,6 @@ password <replaceable>my-password</replaceable>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
</para>
|
</para>
|
||||||
|
|
|
@ -313,6 +313,14 @@ public:
|
||||||
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."};
|
||||||
|
|
||||||
|
Setting<unsigned int> ttlNegativeNarInfoCache{this, 3600, "narinfo-cache-negative-ttl",
|
||||||
|
"The TTL in seconds for negative lookups in the disk cache i.e binary cache lookups that "
|
||||||
|
"return an invalid path result"};
|
||||||
|
|
||||||
|
Setting<unsigned int> ttlPositiveNarInfoCache{this, 30 * 24 * 3600, "narinfo-cache-positive-ttl",
|
||||||
|
"The TTL in seconds for positive lookups in the disk cache i.e binary cache lookups that "
|
||||||
|
"return a valid path result."};
|
||||||
|
|
||||||
/* ?Who we trust to use the daemon in safe ways */
|
/* ?Who we trust to use the daemon in safe ways */
|
||||||
Setting<Strings> allowedUsers{this, {"*"}, "allowed-users",
|
Setting<Strings> allowedUsers{this, {"*"}, "allowed-users",
|
||||||
"Which users or groups are allowed to connect to the daemon."};
|
"Which users or groups are allowed to connect to the daemon."};
|
||||||
|
|
|
@ -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.ttlNegativeNarInfoCache)
|
||||||
(now - ttlPositive)
|
(now - settings.ttlPositiveNarInfoCache)
|
||||||
.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.ttlNegativeNarInfoCache)
|
||||||
(now - ttlPositive));
|
(now - settings.ttlPositiveNarInfoCache));
|
||||||
|
|
||||||
if (!queryNAR.next())
|
if (!queryNAR.next())
|
||||||
return {oUnknown, 0};
|
return {oUnknown, 0};
|
||||||
|
|
Loading…
Reference in a new issue