SharedFile TeaSafe::setAndGetCachedFile(std::string const &path, SharedCompoundFolder const &parentEntry, OpenDisposition openMode) const { // very strictly limit the size of the cache to being able to hold // on to one entry only. TODO. does this mean that a map is a map // idea? We could just use a single pair. if(m_fileCache.size() > 1) { FileCache().swap(m_fileCache); } auto it(m_fileCache.find(path)); if(it != m_fileCache.end()) { // note: need to also check if the openMode is different to the cached // version in which case the cached version should probably be rebuilt if(!it->second->getOpenDisposition().equals(openMode)) { m_fileCache.erase(path); } else { return it->second; } } auto sf(std::make_shared<File>(parentEntry->getFile(boost::filesystem::path(path).filename().string(), openMode))); m_fileCache.insert(std::make_pair(path, sf)); return sf; }
void CoreFS::setCachedFile(std::string const &path, SharedCompoundFolder const &parentEntry, OpenDisposition openMode) const { auto theName = boost::filesystem::path(path).filename().string(); if(m_cachedFileAndPath) { if( m_cachedFileAndPath->first != path || !m_cachedFileAndPath->second->getOpenDisposition().equals(openMode)) { m_cachedFileAndPath->second = std::make_shared<File>(parentEntry->getFile(theName, openMode)); } } else { m_cachedFileAndPath.reset(new FileAndPathPair(path, std::make_shared<File>(parentEntry->getFile(theName, openMode)))); } }
void CoreFS::removeAllChildFoldersToo(::boost::filesystem::path const &path, SharedCompoundFolder const &f) { std::vector<SharedEntryInfo> infos = f->listFolderEntries(); for (auto const & entry : infos) { auto entryPath = path; entryPath /= entry->filename(); removeFolderFromCache(entryPath); } }