Reduce load delay with many recent http files.

If we have data for them, we can start up fairly quickly.
This commit is contained in:
Unknown W. Brackets 2016-06-26 20:45:04 -07:00
parent 9d6684a776
commit eb674b4699
2 changed files with 20 additions and 0 deletions

View File

@ -54,6 +54,11 @@ DiskCachingFileLoader::~DiskCachingFileLoader() {
}
bool DiskCachingFileLoader::Exists() {
if (cache_->HasData()) {
// It may require a slow operation to check - if we have data, let's say yes.
// This helps initial load, since we check each recent file for existence.
return true;
}
return backend_->Exists();
}
@ -718,6 +723,19 @@ void DiskCachingFileLoaderCache::CloseFileHandle() {
fd_ = 0;
}
bool DiskCachingFileLoaderCache::HasData() const {
if (!f_) {
return false;
}
for (size_t i = 0; i < blockIndexLookup_.size(); ++i) {
if (blockIndexLookup_[i] != INVALID_INDEX) {
return true;
}
}
return false;
}
u64 DiskCachingFileLoaderCache::FreeDiskSpace() {
std::string dir = cacheDir_;
if (dir.empty()) {

View File

@ -89,6 +89,8 @@ public:
// Guaranteed to read at least one block into the cache.
size_t SaveIntoCache(FileLoader *backend, s64 pos, size_t bytes, void *data);
bool HasData() const;
private:
void InitCache(const std::string &path);
void ShutdownCache();