Exemple #1
0
LLVOCache::~LLVOCache()
{
	if(mEnabled)
	{
		writeCacheHeader();
		clearCacheInMemory();
	}
}
Exemple #2
0
LLVOCache::~LLVOCache()
{
	if(mEnabled)
	{
		writeCacheHeader();
		clearCacheInMemory();
	}
	delete mLocalAPRFilePoolp;
}
Exemple #3
0
void LLVOCache::removeCache() 
{
	llassert_always(mInitialized) ;
	if(mReadOnly)
	{
		return ;
	}

	std::string delem = gDirUtilp->getDirDelimiter();
	std::string mask = delem + "*";
	gDirUtilp->deleteFilesInDir(mObjectCacheDirName, mask); 

	clearCacheInMemory() ;
	writeCacheHeader();
}
Exemple #4
0
void LLVOCache::purgeEntries()
{
	U32 limit = mCacheSize - NUM_ENTRIES_TO_PURGE ;
	while(mHeaderEntryQueue.size() > limit)
	{
		header_entry_queue_t::iterator iter = mHeaderEntryQueue.begin() ;
		HeaderEntryInfo* entry = *iter ;
		
		removeFromCache(entry->mHandle) ;
		mHandleEntryMap.erase(entry->mHandle) ;		
		mHeaderEntryQueue.erase(iter) ;
		delete entry ;
	}

	writeCacheHeader() ;
	readCacheHeader() ;
	mNumEntries = mHandleEntryMap.size() ;
}
Exemple #5
0
void LLVOCache::removeCache() 
{
	llassert_always(mInitialized) ;
	if(mReadOnly)
	{
		llwarns << "Not clearing object cache: Cache is currently in read-only mode." << llendl;
		return ;
	}

	llinfos << "about to remove the object cache due to some error." << llendl ;

	std::string mask = "*";
	llinfos << "Removing cache at " << mObjectCacheDirName << llendl;
	gDirUtilp->deleteFilesInDir(mObjectCacheDirName, mask); 

	clearCacheInMemory() ;
	writeCacheHeader();
}
Exemple #6
0
void LLVOCache::readCacheHeader()
{
	//clear stale info.
	clearCacheInMemory();	

	if (LLAPRFile::isExist(mHeaderFileName, mLocalAPRFilePoolp))
	{
		LLAPRFile* apr_file = new LLAPRFile(mHeaderFileName, APR_READ|APR_BINARY, mLocalAPRFilePoolp);		
		
		//read the meta element
		if(!checkRead(apr_file, &mMetaInfo, sizeof(HeaderMetaInfo)))
		{
			return ;
		}

		HeaderEntryInfo* entry ;
		mNumEntries = 0 ;
		while(mNumEntries < MAX_NUM_OBJECT_ENTRIES)
		{
			entry = new HeaderEntryInfo() ;
			if(!checkRead(apr_file, entry, sizeof(HeaderEntryInfo)))
			{
				delete entry ;			
				return ;
			}
			else if(!entry->mTime) //end of the cache.
			{
				delete entry ;
				return ;
			}

			entry->mIndex = mNumEntries++ ;
			mHeaderEntryQueue.insert(entry) ;
			mHandleEntryMap[entry->mHandle] = entry ;
		}

		delete apr_file ;
	}
	else
	{
		writeCacheHeader() ;
	}
}
Exemple #7
0
void LLVOCache::readCacheHeader()
{
	if(!mEnabled)
	{
		llwarns << "Not reading cache header: Cache is currently disabled." << llendl;
		return;
	}

	//clear stale info.
	clearCacheInMemory();	

	bool success = true ;
	if (LLAPRFile::isExist(mHeaderFileName, mLocalAPRFilePoolp))
	{
		LLAPRFile apr_file(mHeaderFileName, APR_READ|APR_BINARY, mLocalAPRFilePoolp);		
		
		//read the meta element
		success = check_read(&apr_file, &mMetaInfo, sizeof(HeaderMetaInfo)) ;
		
		if(success)
		{
			HeaderEntryInfo* entry = NULL ;
			mNumEntries = 0 ;
			U32 num_read = 0 ;
			while(num_read++ < MAX_NUM_OBJECT_ENTRIES)
			{
				if(!entry)
				{
					entry = new HeaderEntryInfo() ;
				}
				success = check_read(&apr_file, entry, sizeof(HeaderEntryInfo));
								
				if(!success) //failed
				{
					llwarns << "Error reading cache header entry. (entry_index=" << mNumEntries << ")" << llendl;
					delete entry ;
					entry = NULL ;
					break ;
				}
				else if(entry->mTime == INVALID_TIME)
				{
					continue ; //an empty entry
				}

				entry->mIndex = mNumEntries++ ;
				mHeaderEntryQueue.insert(entry) ;
				mHandleEntryMap[entry->mHandle] = entry ;
				entry = NULL ;
			}
			if(entry)
			{
				delete entry ;
			}
		}

		//---------
		//debug code
		//----------
		//std::string name ;
		//for(header_entry_queue_t::iterator iter = mHeaderEntryQueue.begin() ; success && iter != mHeaderEntryQueue.end(); ++iter)
		//{
		//	getObjectCacheFilename((*iter)->mHandle, name) ;
		//	llinfos << name << llendl ;
		//}
		//-----------
	}
	else
	{
		writeCacheHeader() ;
	}

	if(!success)
	{
		removeCache() ; //failed to read header, clear the cache
	}
	else if(mNumEntries >= mCacheSize)
	{
		purgeEntries(mCacheSize) ;
	}

	return ;
}