diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-01-27 13:17:08 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-01-27 13:17:08 +0100 |
commit | 211bc7f0e6daa65fe4083334e2411bc441067904 (patch) | |
tree | 105c13d4692005dead850adee4381767a5bf7b16 /src/libstore/nar-info-disk-cache.cc | |
parent | f57a38b109dbea26239a1cc001ff4b608006af6d (diff) |
Implement TTL for binary cache lookups
Diffstat (limited to 'src/libstore/nar-info-disk-cache.cc')
-rw-r--r-- | src/libstore/nar-info-disk-cache.cc | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index ff4bd651a..ed2f18ffe 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -42,8 +42,9 @@ class NarInfoDiskCacheImpl : public NarInfoDiskCache { public: - /* How long negative lookups are valid. */ + /* How long negative and positive lookups are valid. */ const int ttlNegative = 3600; + const int ttlPositive = 30 * 24 * 3600; struct Cache { @@ -94,7 +95,7 @@ public: "insert or replace into NARs(cache, hashPart, timestamp, present) values (?, ?, ?, 0)"); 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) @@ -143,7 +144,13 @@ public: 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()) return {oUnknown, 0}; @@ -153,8 +160,6 @@ public: auto narInfo = make_ref<NarInfo>(); - // FIXME: implement TTL. - auto namePart = queryNAR.getStr(2); narInfo->path = cache.storeDir + "/" + hashPart + (namePart.empty() ? "" : "-" + namePart); |