Accelerated aging for special occasions.

This commit is contained in:
JoelKatz
2013-01-08 01:33:40 -08:00
parent 79c3f777aa
commit 5eeef9d3fd

View File

@@ -107,13 +107,26 @@ template<typename c_Key, typename c_Data> void TaggedCache<c_Key, c_Data>::sweep
{
boost::recursive_mutex::scoped_lock sl(mLock);
mLastSweep = time(NULL);
time_t mLastSweep = time(NULL);
time_t target = mLastSweep - mTargetAge;
// Pass 1, remove old objects from cache
int cacheRemovals = 0;
if ((mTargetSize == 0) || (mCache.size() > mTargetSize))
{
if (mTargetSize != 0)
{
target = mLastSweep - (mTargetAge * mCache.size() / mTargetSize);
if (target > (mLastSweep - 2))
target = mLastSweep - 2;
Log(lsINFO, TaggedCachePartition) << mName << " is growing fast " <<
mCache.size() << " of " << mTargetSize <<
" aging at " << (mLastSweep - target) << " of " << mTargetAge;
}
else
target = mLastSweep - mTargetAge;
cache_iterator cit = mCache.begin();
while (cit != mCache.end())
{