diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-01-05 21:24:14 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-01-05 21:24:14 +0000 | 
| commit | 6e4d5fbe3a1ed3eba68cf9c484f62259d7890243 (patch) | |
| tree | 0360d8efb7983e94f246e0c0f60042c559b947b9 | |
| parent | Add support explicitly removing an item from the cache (diff) | |
| download | libadhocutil-6e4d5fbe3a1ed3eba68cf9c484f62259d7890243.tar.bz2 libadhocutil-6e4d5fbe3a1ed3eba68cf9c484f62259d7890243.tar.xz libadhocutil-6e4d5fbe3a1ed3eba68cf9c484f62259d7890243.zip  | |
Add support explicitly clearing all items from the cache
| -rw-r--r-- | libadhocutil/cache.h | 2 | ||||
| -rw-r--r-- | libadhocutil/cache.impl.h | 8 | ||||
| -rw-r--r-- | libadhocutil/unittests/testCache.cpp | 2 | 
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 )  | 
