1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 13:21:47 +02:00
nix/src/libfetchers/input-cache.cc
2025-04-09 22:13:28 +02:00

41 lines
995 B
C++

#include "nix/fetchers/input-cache.hh"
#include "nix/util/sync.hh"
namespace nix::fetchers {
struct InputCacheImpl : InputCache
{
Sync<std::map<Input, CachedInput>> cache_;
std::optional<CachedInput> lookup(const Input & originalInput) const override
{
auto cache(cache_.readLock());
auto i = cache->find(originalInput);
if (i == cache->end())
return std::nullopt;
debug(
"mapping '%s' to previously seen input '%s' -> '%s",
originalInput.to_string(),
i->first.to_string(),
i->second.lockedInput.to_string());
return i->second;
}
void upsert(Input key, CachedInput cachedInput) override
{
cache_.lock()->insert_or_assign(std::move(key), std::move(cachedInput));
}
void clear() override
{
cache_.lock()->clear();
}
};
ref<InputCache> InputCache::getCache()
{
static auto cache = make_ref<InputCacheImpl>();
return cache;
}
}