From dea0cc165da9da5a04fa254e7f4a6a52699785c8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 16 Feb 2020 20:38:49 +0100 Subject: [PATCH] input/cache/Manager: add method Flush() --- src/input/cache/Manager.cxx | 16 ++++++++++++++++ src/input/cache/Manager.hxx | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/input/cache/Manager.cxx b/src/input/cache/Manager.cxx index 1a798ca4c..4e8cdb318 100644 --- a/src/input/cache/Manager.cxx +++ b/src/input/cache/Manager.cxx @@ -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 { diff --git a/src/input/cache/Manager.hxx b/src/input/cache/Manager.hxx index 4ff1b5e2f..5df58075f 100644 --- a/src/input/cache/Manager.hxx +++ b/src/input/cache/Manager.hxx @@ -72,6 +72,8 @@ public: explicit InputCacheManager(const InputCacheConfig &config) noexcept; ~InputCacheManager() noexcept; + void Flush() noexcept; + gcc_pure bool Contains(const char *uri) noexcept;