aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/fetchers/cache.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-03-18 15:14:23 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-03-18 15:14:23 +0100
commitc5ec95e2c70d15935d02216852bbc22f87f4f5ed (patch)
tree4e25ab87740448c9014a8e85a0a9c7b6671d1ea1 /src/libstore/fetchers/cache.cc
parent1b494798360cca30971b43adda5baa154bf1991e (diff)
tarball.cc: Use ETags
Diffstat (limited to 'src/libstore/fetchers/cache.cc')
-rw-r--r--src/libstore/fetchers/cache.cc24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/libstore/fetchers/cache.cc b/src/libstore/fetchers/cache.cc
index 4c88b64c5..14a84744a 100644
--- a/src/libstore/fetchers/cache.cc
+++ b/src/libstore/fetchers/cache.cc
@@ -66,6 +66,19 @@ struct CacheImpl : Cache
ref<Store> store,
const Attrs & inAttrs) override
{
+ if (auto res = lookupExpired(store, inAttrs)) {
+ if (!res->expired)
+ return std::make_pair(std::move(res->infoAttrs), std::move(res->storePath));
+ debug("ignoring expired cache entry '%s'",
+ attrsToJson(inAttrs).dump());
+ }
+ return {};
+ }
+
+ std::optional<Result> lookupExpired(
+ ref<Store> store,
+ const Attrs & inAttrs) override
+ {
auto state(_state.lock());
auto inAttrsJson = attrsToJson(inAttrs).dump();
@@ -81,11 +94,6 @@ struct CacheImpl : Cache
auto immutable = stmt.getInt(2) != 0;
auto timestamp = stmt.getInt(3);
- if (!immutable && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0))) {
- debug("ignoring expired cache entry '%s'", inAttrsJson);
- return {};
- }
-
store->addTempRoot(storePath);
if (!store->isValidPath(storePath)) {
// FIXME: we could try to substitute 'storePath'.
@@ -96,7 +104,11 @@ struct CacheImpl : Cache
debug("using cache entry '%s' -> '%s', '%s'",
inAttrsJson, infoJson, store->printStorePath(storePath));
- return {{jsonToAttrs(nlohmann::json::parse(infoJson)), std::move(storePath)}};
+ return Result {
+ .expired = !immutable && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0)),
+ .infoAttrs = jsonToAttrs(nlohmann::json::parse(infoJson)),
+ .storePath = std::move(storePath)
+ };
}
};