Jeck - Stricter cache limits.

This commit is contained in:
wagic.jeck
2009-09-19 22:34:48 +00:00
parent 0d3686e65a
commit 8cc9bff484
2 changed files with 8 additions and 36 deletions

View File

@@ -9,10 +9,10 @@
#include <list>
//Soft limits.
//For values higher than ~8000000, we run the danger of hitting our reserved space in deck editor.
#define HUGE_CACHE_LIMIT 8000000
#define LARGE_CACHE_LIMIT 6000000
#define SMALL_CACHE_LIMIT 3000000
//For values higher than ~6000000, we run the danger of hitting our reserved space in deck editor.
#define HUGE_CACHE_LIMIT 6000000
#define LARGE_CACHE_LIMIT 4000000
#define SMALL_CACHE_LIMIT 2000000
#define HUGE_CACHE_ITEMS 200
#define LARGE_CACHE_ITEMS 150

View File

@@ -1020,36 +1020,6 @@ bool WCache<cacheItem, cacheActual>::AttemptNew(cacheItem* item, int submode){
return false;
}
//Keep a bit of memory in reserve.
if(CACHE_SPACE_RESERVED > 0){
char * test = (char*)malloc(CACHE_SPACE_RESERVED);;
int tries = 0;
while(!test && tries++ < MAX_CACHE_ATTEMPTS){
if(!RemoveOldest())
break;
test = (char*)malloc(CACHE_SPACE_RESERVED);
}
if(test){
free(test);
test = NULL;
}
else{
resources.ClearUnlocked();
test = (char*)malloc(CACHE_SPACE_RESERVED);
if(test){
free(test);
test = NULL;
}
else{
mError = CACHE_ERROR_BAD_ALLOC;
return false;
}
}
}
string filename = makeFilename(item->id,submode);
if(!item->Attempt(filename,submode,mError)){
@@ -1064,7 +1034,7 @@ bool WCache<cacheItem, cacheActual>::AttemptNew(cacheItem* item, int submode){
if(!RemoveOldest())
break;
if(item->Attempt(filename,submode,mError))
if(item->Attempt(filename,submode,mError) && item->isGood())
break;
//Failed attempt. Trash this.
@@ -1072,18 +1042,20 @@ bool WCache<cacheItem, cacheActual>::AttemptNew(cacheItem* item, int submode){
}
if(!item->isGood()){
item->Trash();
Cleanup();
item->Attempt(filename,submode,mError);
}
//Still no result, so clear cache entirely, then try again.
if(!item->isGood()){
item->Trash();
ClearUnlocked();
item->Attempt(filename,submode,mError);
}
}
//Final failure. Trash it.
if(!item->isGood()){
if(item && !item->isGood()){
item->Trash();
mError = CACHE_ERROR_BAD;
return false;