mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 16:26:18 +02:00
Implement TTL for binary cache lookups
This commit is contained in:
parent
f57a38b109
commit
211bc7f0e6
1 changed files with 10 additions and 5 deletions
|
@ -42,8 +42,9 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* How long negative lookups are valid. */
|
/* How long negative and positive lookups are valid. */
|
||||||
const int ttlNegative = 3600;
|
const int ttlNegative = 3600;
|
||||||
|
const int ttlPositive = 30 * 24 * 3600;
|
||||||
|
|
||||||
struct Cache
|
struct Cache
|
||||||
{
|
{
|
||||||
|
@ -94,7 +95,7 @@ public:
|
||||||
"insert or replace into NARs(cache, hashPart, timestamp, present) values (?, ?, ?, 0)");
|
"insert or replace into NARs(cache, hashPart, timestamp, present) values (?, ?, ?, 0)");
|
||||||
|
|
||||||
state->queryNAR.create(state->db,
|
state->queryNAR.create(state->db,
|
||||||
"select * from NARs where cache = ? and hashPart = ?");
|
"select * from NARs where cache = ? and hashPart = ? and ((present = 0 and timestamp > ?) or (present = 1 and timestamp > ?))");
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache & getCache(State & state, const std::string & uri)
|
Cache & getCache(State & state, const std::string & uri)
|
||||||
|
@ -143,7 +144,13 @@ public:
|
||||||
|
|
||||||
auto & cache(getCache(*state, uri));
|
auto & cache(getCache(*state, uri));
|
||||||
|
|
||||||
auto queryNAR(state->queryNAR.use()(cache.id)(hashPart));
|
auto now = time(0);
|
||||||
|
|
||||||
|
auto queryNAR(state->queryNAR.use()
|
||||||
|
(cache.id)
|
||||||
|
(hashPart)
|
||||||
|
(now - ttlNegative)
|
||||||
|
(now - ttlPositive));
|
||||||
|
|
||||||
if (!queryNAR.next())
|
if (!queryNAR.next())
|
||||||
return {oUnknown, 0};
|
return {oUnknown, 0};
|
||||||
|
@ -153,8 +160,6 @@ public:
|
||||||
|
|
||||||
auto narInfo = make_ref<NarInfo>();
|
auto narInfo = make_ref<NarInfo>();
|
||||||
|
|
||||||
// FIXME: implement TTL.
|
|
||||||
|
|
||||||
auto namePart = queryNAR.getStr(2);
|
auto namePart = queryNAR.getStr(2);
|
||||||
narInfo->path = cache.storeDir + "/" +
|
narInfo->path = cache.storeDir + "/" +
|
||||||
hashPart + (namePart.empty() ? "" : "-" + namePart);
|
hashPart + (namePart.empty() ? "" : "-" + namePart);
|
||||||
|
|
Loading…
Reference in a new issue