input/cache/Manager: add method Flush()

This commit is contained in:
Max Kellermann 2020-02-16 20:38:49 +01:00
parent 07e0a31d02
commit dea0cc165d
2 changed files with 18 additions and 0 deletions

View File

@ -58,6 +58,22 @@ InputCacheManager::~InputCacheManager() noexcept
items_by_time.clear_and_dispose(DeleteDisposer());
}
void
InputCacheManager::Flush() noexcept
{
items_by_time.remove_and_dispose_if([](const InputCacheItem &item){
return !item.IsInUse();
}, [this](InputCacheItem *item){
// TODO: eliminate code duplication, see method Remove()
assert(total_size >= item->size());
total_size -= item->size();
items_by_uri.erase(items_by_uri.iterator_to(*item));
delete item;
});
// TODO: invalidate busy items and flush them later
}
bool
InputCacheManager::IsEligible(const InputStream &input) noexcept
{

View File

@ -72,6 +72,8 @@ public:
explicit InputCacheManager(const InputCacheConfig &config) noexcept;
~InputCacheManager() noexcept;
void Flush() noexcept;
gcc_pure
bool Contains(const char *uri) noexcept;