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(); } } }
LLVOCache::~LLVOCache() { if(mEnabled) { writeCacheHeader(); clearCacheInMemory(); } }
LLVOCache::~LLVOCache() { if(mEnabled) { writeCacheHeader(); clearCacheInMemory(); } delete mLocalAPRFilePoolp; }
void LLVOCache::writeCacheHeader() { if (!mEnabled) { llwarns << "Not writing cache header: Cache is currently disabled." << llendl; return; } if(mReadOnly) { llwarns << "Not writing cache header: Cache is currently in read-only mode." << llendl; return; } bool success = true ; { LLAPRFile apr_file(mHeaderFileName, APR_CREATE|APR_WRITE|APR_BINARY, mLocalAPRFilePoolp); //write the meta element success = check_write(&apr_file, &mMetaInfo, sizeof(HeaderMetaInfo)) ; mNumEntries = 0 ; for(header_entry_queue_t::iterator iter = mHeaderEntryQueue.begin() ; success && iter != mHeaderEntryQueue.end(); ++iter) { (*iter)->mIndex = mNumEntries++ ; success = check_write(&apr_file, (void*)*iter, sizeof(HeaderEntryInfo)); } mNumEntries = mHeaderEntryQueue.size() ; if(success && mNumEntries < MAX_NUM_OBJECT_ENTRIES) { HeaderEntryInfo* entry = new HeaderEntryInfo() ; entry->mTime = INVALID_TIME ; for(S32 i = mNumEntries ; success && i < MAX_NUM_OBJECT_ENTRIES ; i++) { //fill the cache with the default entry. success = check_write(&apr_file, entry, sizeof(HeaderEntryInfo)) ; } delete entry ; } } if(!success) { clearCacheInMemory() ; mReadOnly = TRUE ; //disable the cache. } return ; }
void LLVOCache::removeCache() { llassert_always(mInitialized) ; if(mReadOnly) { return ; } std::string delem = gDirUtilp->getDirDelimiter(); std::string mask = delem + "*"; gDirUtilp->deleteFilesInDir(mObjectCacheDirName, mask); clearCacheInMemory() ; writeCacheHeader(); }
void LLVOCache::removeCache(ELLPath location) { if(mReadOnly) { return ; } std::string delem = gDirUtilp->getDirDelimiter(); std::string mask = delem + "*"; std::string cache_dir = gDirUtilp->getExpandedFilename(location, object_cache_dirname); gDirUtilp->deleteFilesInDir(cache_dir, mask); //delete all files LLFile::rmdir(cache_dir); clearCacheInMemory(); mInitialized = FALSE ; }
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(); }
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() ; } }
void LLVOCache::removeCache(ELLPath location) { if(mReadOnly) { llwarns << "Not removing cache at " << location << ": Cache is currently in read-only mode." << llendl; return ; } llinfos << "about to remove the object cache due to settings." << llendl ; std::string mask = "*"; std::string cache_dir = gDirUtilp->getExpandedFilename(location, object_cache_dirname); llinfos << "Removing cache at " << cache_dir << llendl; gDirUtilp->deleteFilesInDir(cache_dir, mask); //delete all files LLFile::rmdir(cache_dir); clearCacheInMemory(); mInitialized = FALSE ; }
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(); } } }
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 ; }