From 2a14079563ce323452a8088cca994e4f5c0edcd4 Mon Sep 17 00:00:00 2001
From: Xiaohong Bao <bao@lindenlab.com>
Date: Mon, 24 Jan 2011 15:50:46 -0700
Subject: [PATCH] fix for SH-445: debug settings ->
 "CacheNumberOfRegionsForObjects" does not limit the number of object cache
 files

---
 indra/newview/app_settings/settings.xml |  2 +-
 indra/newview/llvocache.cpp             | 20 +++++++++++++-------
 indra/newview/llvocache.h               |  2 +-
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 819808ec400..ced46c72949 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -1179,7 +1179,7 @@
       <key>Type</key>
       <string>U32</string>
       <key>Value</key>
-      <integer>20000</integer>
+      <integer>128</integer>
     </map>
     <key>CacheSize</key>
     <map>
diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp
index 1e2736f7d93..b3312db4a0b 100644
--- a/indra/newview/llvocache.cpp
+++ b/indra/newview/llvocache.cpp
@@ -517,6 +517,11 @@ void LLVOCache::readCacheHeader()
 	{
 		removeCache() ; //failed to read header, clear the cache
 	}
+	else if(mNumEntries >= mCacheSize)
+	{
+		purgeEntries(mCacheSize) ;
+	}
+
 	return ;
 }
 
@@ -644,9 +649,9 @@ void LLVOCache::readFromCache(U64 handle, const LLUUID& id, LLVOCacheEntry::voca
 	return ;
 }
 	
-void LLVOCache::purgeEntries()
+void LLVOCache::purgeEntries(U32 size)
 {
-	while(mHeaderEntryQueue.size() >= mCacheSize)
+	while(mHeaderEntryQueue.size() >= size)
 	{
 		header_entry_queue_t::iterator iter = mHeaderEntryQueue.begin() ;
 		HeaderEntryInfo* entry = *iter ;			
@@ -671,16 +676,17 @@ void LLVOCache::writeToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry:
 	{
 		llwarns << "Not writing cache for handle " << handle << "): Cache is currently in read-only mode." << llendl;
 		return ;
-	}
-	if(mNumEntries >= mCacheSize)
-	{
-		purgeEntries() ;
-	}
+	}	
 
 	HeaderEntryInfo* entry;
 	handle_entry_map_t::iterator iter = mHandleEntryMap.find(handle) ;
 	if(iter == mHandleEntryMap.end()) //new entry
 	{				
+		if(mNumEntries >= mCacheSize - 1)
+		{
+			purgeEntries(mCacheSize - 1) ;
+		}
+
 		entry = new HeaderEntryInfo();
 		entry->mHandle = handle ;
 		entry->mTime = time(NULL) ;
diff --git a/indra/newview/llvocache.h b/indra/newview/llvocache.h
index 1070fcaae97..14e3b4c7935 100644
--- a/indra/newview/llvocache.h
+++ b/indra/newview/llvocache.h
@@ -130,7 +130,7 @@ class LLVOCache
 	void clearCacheInMemory();
 	void removeCache() ;
 	void removeEntry(HeaderEntryInfo* entry) ;
-	void purgeEntries();
+	void purgeEntries(U32 size);
 	BOOL updateEntry(const HeaderEntryInfo* entry);
 	
 private:
-- 
GitLab