Esempio n. 1
0
void LLVOCache::initCache(ELLPath location, U32 size, U32 cache_version)
{
	if(mInitialized)
	{
		return ;
	}

	setDirNames(location);
	if (!mReadOnly)
	{
		LLFile::mkdir(mObjectCacheDirName);
	}	
	mCacheSize = llclamp(size,
			     MAX_NUM_OBJECT_ENTRIES, NUM_ENTRIES_TO_PURGE);

	mMetaInfo.mVersion = cache_version;
	readCacheHeader();
	mInitialized = TRUE ;

	if(mMetaInfo.mVersion != cache_version) 
	{
		mMetaInfo.mVersion = cache_version ;
		if(mReadOnly) //disable cache
		{
			clearCacheInMemory();
		}
		else //delete the current cache if the format does not match.
		{			
			removeCache();
		}
	}	
}
Esempio n. 2
0
void ItemDelegate::rowsRemoved(const QModelIndex &, int start, int end)
{
    for( int i = end; i >= start; --i ) {
        removeCache(i);
        m_cache.removeAt(i);
    }
}
Esempio n. 3
0
void ItemDelegate::dataChanged(const QModelIndex &a, const QModelIndex &b)
{
    // recalculating sizes of many items is expensive (when searching)
    // - assume that highlighted (matched) text has same size
    // - recalculate size only if item edited
    int row = a.row();
    if ( row == b.row() ) {
        removeCache(row);
        emit sizeHintChanged(a);
    }
}
Esempio n. 4
0
BOOL LLVOCache::checkWrite(LLAPRFile* apr_file, void* src, S32 n_bytes) 
{
	if(!check_write(apr_file, src, n_bytes))
	{
		delete apr_file ;
		removeCache() ;
		return FALSE ;
	}

	return TRUE ;
}
Esempio n. 5
0
void LLVOCache::initCache(ELLPath location, U32 size, U32 cache_version)
{
	if(!mEnabled)
	{
		llwarns << "Not initializing cache: Cache is currently disabled." << llendl;
		return ;
	}

	if(mInitialized)
	{
		llwarns << "Cache already initialized." << llendl;
		return ;
	}
	mInitialized = TRUE ;

	setDirNames(location);
	if (!mReadOnly)
	{
		LLFile::mkdir(mObjectCacheDirName);
	}
	mCacheSize = llclamp(size, MIN_ENTRIES_TO_PURGE, MAX_NUM_OBJECT_ENTRIES);
	mMetaInfo.mVersion = cache_version;
	readCacheHeader();	

	if(mMetaInfo.mVersion != cache_version) 
	{
		mMetaInfo.mVersion = cache_version ;
		if(mReadOnly) //disable cache
		{
			clearCacheInMemory();
		}
		else //delete the current cache if the format does not match.
		{			
			removeCache();
		}
	}	
}
Esempio n. 6
0
void ItemDelegate::invalidateCache()
{
    for( int i = 0; i < m_cache.length(); ++i )
        removeCache(i);
}
Esempio n. 7
0
void ItemDelegate::removeCache(const QModelIndex &index)
{
    removeCache(index.row());
}
Esempio n. 8
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 ;
}
Esempio n. 9
0
void LLVOCache::writeToCache(U64 handle, const LLUUID& id, const LLVOCacheEntry::vocache_entry_map_t& cache_entry_map, BOOL dirty_cache) 
{
	llassert_always(mInitialized);

	if(mReadOnly)
	{
		return ;
	}

	HeaderEntryInfo* entry;
	handle_entry_map_t::iterator iter = mHandleEntryMap.find(handle) ;
	if(iter == mHandleEntryMap.end()) //new entry
	{		
		if(mNumEntries >= mCacheSize)
		{
			purgeEntries() ;
		}
		
		entry = new HeaderEntryInfo();
		entry->mHandle = handle ;
		entry->mTime = time(NULL) ;
		entry->mIndex = mNumEntries++ ;
		mHeaderEntryQueue.insert(entry) ;
		mHandleEntryMap[handle] = entry ;
	}
	else
	{
		entry = iter->second ;
		entry->mTime = time(NULL) ;

		//resort
		mHeaderEntryQueue.erase(entry) ;
		mHeaderEntryQueue.insert(entry) ;
	}

	//update cache header
	if(!updateEntry(entry))
	{
		return ; //update failed.
	}

	if(!dirty_cache)
	{
		return ; //nothing changed, no need to update.
	}

	//write to cache file
	std::string filename;
	getObjectCacheFilename(handle, filename);
	LLAPRFile* apr_file = new LLAPRFile(filename, APR_CREATE|APR_WRITE|APR_BINARY, mLocalAPRFilePoolp);
	
	if(!checkWrite(apr_file, (void*)id.mData, UUID_BYTES))
	{
		return ;
	}

	S32 num_entries = cache_entry_map.size() ;
	if(!checkWrite(apr_file, &num_entries, sizeof(S32)))
	{
		return ;
	}

	for (LLVOCacheEntry::vocache_entry_map_t::const_iterator iter = cache_entry_map.begin(); iter != cache_entry_map.end(); ++iter)
	{
		if(!iter->second->writeToFile(apr_file))
		{
			//failed
			delete apr_file ;
			removeCache() ;
			return ;
		}
	}

	delete apr_file ;
	return ;
}