libfetchers: Add CachingFilteringInputAccessor
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
This commit is contained in:
parent
f68ad5acbb
commit
d80c582b78
|
@ -80,4 +80,13 @@ ref<AllowListInputAccessor> AllowListInputAccessor::create(
|
||||||
return make_ref<AllowListInputAccessorImpl>(next, std::move(allowedPaths), std::move(makeNotAllowedError));
|
return make_ref<AllowListInputAccessorImpl>(next, std::move(allowedPaths), std::move(makeNotAllowedError));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CachingFilteringInputAccessor::isAllowed(const CanonPath & path)
|
||||||
|
{
|
||||||
|
auto i = cache.find(path);
|
||||||
|
if (i != cache.end()) return i->second;
|
||||||
|
auto res = isAllowedUncached(path);
|
||||||
|
cache.emplace(path, res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,4 +71,18 @@ struct AllowListInputAccessor : public FilteringInputAccessor
|
||||||
using FilteringInputAccessor::FilteringInputAccessor;
|
using FilteringInputAccessor::FilteringInputAccessor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapping `InputAccessor` mix-in where `isAllowed()` caches the result of virtual `isAllowedUncached()`.
|
||||||
|
*/
|
||||||
|
struct CachingFilteringInputAccessor : FilteringInputAccessor
|
||||||
|
{
|
||||||
|
std::map<CanonPath, bool> cache;
|
||||||
|
|
||||||
|
using FilteringInputAccessor::FilteringInputAccessor;
|
||||||
|
|
||||||
|
bool isAllowed(const CanonPath & path) override;
|
||||||
|
|
||||||
|
virtual bool isAllowedUncached(const CanonPath & path) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue