Skip to content

Commit

Permalink
Merge pull request #1080 from rouault/vsicurl_lru_cache
Browse files Browse the repository at this point in the history
 /vsicurl/ and derived: implement a LRU cache for file properties and directory content listing
  • Loading branch information
rouault committed Nov 8, 2018
2 parents 0c16944 + d461b1b commit c1985e7
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 340 deletions.
10 changes: 10 additions & 0 deletions gdal/port/cpl_mem_cache.h
Expand Up @@ -172,6 +172,16 @@ class Cache {
return cache_.find(k) != cache_.end();
}

bool getOldestEntry(Key& kOut, Value& vOut) {
Guard g(lock_);
if( keys_.empty() ) {
return false;
}
kOut = keys_.back().key;
vOut = keys_.back().value;
return true;
}

size_t getMaxSize() const { return maxSize_; }
size_t getElasticity() const { return elasticity_; }
size_t getMaxAllowedSize() const { return maxSize_ + elasticity_; }
Expand Down
12 changes: 6 additions & 6 deletions gdal/port/cpl_vsil_az.cpp
Expand Up @@ -83,7 +83,7 @@ void VSICurlFilesystemHandler::AnalyseAzureFileList(
return;
CPLXMLNode* psEnumerationResults = CPLGetXMLNode(psTree, "=EnumerationResults");

std::vector< std::pair<CPLString, CachedFileProp> > aoProps;
std::vector< std::pair<CPLString, FileProp> > aoProps;
// Count the number of occurrences of a path. Can be 1 or 2. 2 in the case
// that both a filename and directory exist
std::map<CPLString, int> aoNameCount;
Expand Down Expand Up @@ -115,7 +115,7 @@ void VSICurlFilesystemHandler::AnalyseAzureFileList(
{
bNonEmpty = true;

CachedFileProp prop;
FileProp prop;
prop.eExists = EXIST_YES;
prop.bHasComputedFileSize = true;
prop.fileSize = static_cast<GUIntBig>(
Expand Down Expand Up @@ -148,7 +148,7 @@ void VSICurlFilesystemHandler::AnalyseAzureFileList(
}

aoProps.push_back(
std::pair<CPLString, CachedFileProp>
std::pair<CPLString, FileProp>
(pszKey + osPrefix.size(), prop));
aoNameCount[pszKey + osPrefix.size()] ++;
}
Expand All @@ -166,15 +166,15 @@ void VSICurlFilesystemHandler::AnalyseAzureFileList(
osKey.resize(osKey.size()-1);
if( osKey.size() > osPrefix.size() )
{
CachedFileProp prop;
FileProp prop;
prop.eExists = EXIST_YES;
prop.bIsDirectory = true;
prop.bHasComputedFileSize = true;
prop.fileSize = 0;
prop.mTime = 0;

aoProps.push_back(
std::pair<CPLString, CachedFileProp>
std::pair<CPLString, FileProp>
(osKey.c_str() + osPrefix.size(), prop));
aoNameCount[osKey.c_str() + osPrefix.size()] ++;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ void VSICurlFilesystemHandler::AnalyseAzureFileList(
#if DEBUG_VERBOSE
CPLDebug("AZURE", "Cache %s", osCachedFilename.c_str());
#endif
*GetCachedFileProp(osCachedFilename) = aoProps[i].second;
SetCachedFileProp(osCachedFilename, aoProps[i].second);
}
osFileList.AddString( (aoProps[i].first + osSuffix).c_str() );
}
Expand Down

0 comments on commit c1985e7

Please sign in to comment.