summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libadhocutil/cache.h2
-rw-r--r--libadhocutil/cache.impl.h8
-rw-r--r--libadhocutil/unittests/testCache.cpp2
3 files changed, 12 insertions, 0 deletions
diff --git a/libadhocutil/cache.h b/libadhocutil/cache.h
index 72ad879..a394e92 100644
--- a/libadhocutil/cache.h
+++ b/libadhocutil/cache.h
@@ -95,6 +95,8 @@ class DLL_PUBLIC Cache {
/** Explicitly remove an item from the cache.
* @param k Cache key to remove. */
void remove(const K & k);
+ /** Explicitly remove ALL items from the cache. */
+ void clear();
private:
void DLL_PRIVATE prune() const;
diff --git a/libadhocutil/cache.impl.h b/libadhocutil/cache.impl.h
index c07d9c0..0a2b0b3 100644
--- a/libadhocutil/cache.impl.h
+++ b/libadhocutil/cache.impl.h
@@ -127,6 +127,14 @@ Cache<T, K>::remove(const K & k)
template<typename T, typename K>
void
+Cache<T, K>::clear()
+{
+ Lock(lock);
+ cached.clear();
+}
+
+template<typename T, typename K>
+void
Cache<T, K>::prune() const
{
auto now = time(NULL);
diff --git a/libadhocutil/unittests/testCache.cpp b/libadhocutil/unittests/testCache.cpp
index 1f41836..914d282 100644
--- a/libadhocutil/unittests/testCache.cpp
+++ b/libadhocutil/unittests/testCache.cpp
@@ -83,6 +83,8 @@ BOOST_AUTO_TEST_CASE( multivalues )
BOOST_REQUIRE(!tc.get("key1"));
BOOST_REQUIRE_EQUAL(2, *tc.get("key2"));
BOOST_REQUIRE_EQUAL(3, *tc.get("key3"));
+ tc.clear();
+ BOOST_REQUIRE_EQUAL(0, tc.size());
}
BOOST_AUTO_TEST_CASE( expired )