mirror of
				https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
				synced 2025-10-31 02:27:56 +00:00 
			
		
		
		
	fixed GH #2738: Poco::AccessExpireStrategy::onGet() must not extend expiration time after expiration
This commit is contained in:
		| @@ -54,6 +54,8 @@ public: | ||||
| 		// get triggers an update to the expiration time | ||||
| 		typename ExpireStrategy<TKey, TValue>::Iterator it = this->_keys.find(key); | ||||
| 		if (it != this->_keys.end()) | ||||
| 		{ | ||||
| 			if (!it->second->first.isElapsed(this->_expireTime)) // don't extend if already expired | ||||
| 			{ | ||||
| 				this->_keyIndex.erase(it->second); | ||||
| 				Timestamp now; | ||||
| @@ -62,6 +64,7 @@ public: | ||||
| 				it->second = itIdx; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -187,6 +187,21 @@ void ExpireCacheTest::testExpireWithHas() | ||||
| } | ||||
|  | ||||
|  | ||||
| void ExpireCacheTest::testAccessExpireGet() | ||||
| { | ||||
| 	AccessExpireCache<int, int> aCache(DURSLEEP); | ||||
| 	aCache.add(1, 2); // 1 | ||||
| 	assert (aCache.has(1)); | ||||
| 	SharedPtr<int> tmp = aCache.get(1); | ||||
| 	assert (!tmp.isNull()); | ||||
| 	assert (*tmp == 2); | ||||
| 	assert (aCache.size() == 1); | ||||
| 	Thread::sleep(DURWAIT); | ||||
| 	tmp = aCache.get(1); | ||||
| 	assert (tmp.isNull()); | ||||
| } | ||||
|  | ||||
|  | ||||
| void ExpireCacheTest::setUp() | ||||
| { | ||||
| } | ||||
| @@ -207,6 +222,7 @@ CppUnit::Test* ExpireCacheTest::suite() | ||||
| 	CppUnit_addTest(pSuite, ExpireCacheTest, testDuplicateAdd); | ||||
| 	CppUnit_addTest(pSuite, ExpireCacheTest, testAccessExpireN); | ||||
| 	CppUnit_addTest(pSuite, ExpireCacheTest, testExpireWithHas); | ||||
| 	CppUnit_addTest(pSuite, ExpireCacheTest, testAccessExpireGet); | ||||
|  | ||||
| 	return pSuite; | ||||
| } | ||||
|   | ||||
| @@ -29,7 +29,7 @@ public: | ||||
| 	void testExpireN(); | ||||
| 	void testAccessExpireN(); | ||||
| 	void testExpireWithHas(); | ||||
|  | ||||
| 	void testAccessExpireGet(); | ||||
|  | ||||
| 	void setUp(); | ||||
| 	void tearDown(); | ||||
|   | ||||
| @@ -303,6 +303,20 @@ void ExpireLRUCacheTest::testDuplicateAdd() | ||||
| } | ||||
|  | ||||
|  | ||||
| void ExpireLRUCacheTest::testAccessExpireGet() | ||||
| { | ||||
| 	ExpireLRUCache<int, int> aCache(3, DURSLEEP); | ||||
| 	aCache.add(1, 2); // 1 | ||||
| 	assert (aCache.has(1)); | ||||
| 	SharedPtr<int> tmp = aCache.get(1); | ||||
| 	assert (!tmp.isNull()); | ||||
| 	assert (*tmp == 2); | ||||
| 	Thread::sleep(DURWAIT); | ||||
| 	tmp = aCache.get(1); | ||||
| 	assert (tmp.isNull()); | ||||
| } | ||||
|  | ||||
|  | ||||
| void ExpireLRUCacheTest::setUp() | ||||
| { | ||||
| } | ||||
| @@ -326,6 +340,7 @@ CppUnit::Test* ExpireLRUCacheTest::suite() | ||||
| 	CppUnit_addTest(pSuite, ExpireLRUCacheTest, testCacheSize2); | ||||
| 	CppUnit_addTest(pSuite, ExpireLRUCacheTest, testCacheSizeN); | ||||
| 	CppUnit_addTest(pSuite, ExpireLRUCacheTest, testDuplicateAdd); | ||||
| 	CppUnit_addTest(pSuite, ExpireLRUCacheTest, testAccessExpireGet); | ||||
|  | ||||
| 	return pSuite; | ||||
| } | ||||
|   | ||||
| @@ -32,6 +32,7 @@ public: | ||||
| 	void testCacheSize2(); | ||||
| 	void testCacheSizeN(); | ||||
| 	void testDuplicateAdd(); | ||||
| 	void testAccessExpireGet(); | ||||
|  | ||||
| 	void setUp(); | ||||
| 	void tearDown(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Günter Obiltschnig
					Günter Obiltschnig