From 2cb869dfd2e8daa56a8494b42e96edc7793d2a94 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sat, 11 Oct 2025 02:13:49 +0900 Subject: [PATCH] The Truncate method of the StaCache class has been consolidated (#2729) --- src/cache.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cache.cpp b/src/cache.cpp index 4a1c380..9daa0ab 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -122,8 +122,8 @@ bool StatCache::AddStatHasLock(const std::string& key, const struct stat* pstbuf } // Truncate cache(if over cache size) - if(!pMountPointDir->TruncateCache()){ - S3FS_PRN_DBG("There was no cache to truncate."); + if(TruncateCacheHasLock(true)){ + S3FS_PRN_DBG("Some expired caches have been truncated."); } S3FS_PRN_INFO3("add stat cache entry[path=%s]", key.c_str()); @@ -213,8 +213,8 @@ bool StatCache::AddNegativeStat(const std::string& key) } // Truncate cache(if over cache size) - if(!pMountPointDir->TruncateCache()){ - S3FS_PRN_DBG("There was no cache to truncate."); + if(TruncateCacheHasLock(true)){ + S3FS_PRN_DBG("Some expired caches have been truncated."); } S3FS_PRN_INFO3("add negative cache entry[path=%s]", key.c_str()); @@ -250,10 +250,11 @@ void StatCache::ClearNoTruncateFlag(const std::string& key) bool StatCache::TruncateCacheHasLock(bool check_only_oversize_case) { if(check_only_oversize_case && StatCacheNode::GetCacheCount() <= GetCacheSize()){ - return true; + return false; } if(!pMountPointDir->TruncateCache()){ S3FS_PRN_DBG("could not truncate any cache[current size=%lu, maximum size=%lu]", StatCacheNode::GetCacheCount(), GetCacheSize()); + return false; } // for debug @@ -357,8 +358,8 @@ bool StatCache::AddSymlink(const std::string& key, const struct stat& stbuf, con } // Truncate cache(if over cache size) - if(!pMountPointDir->TruncateCache()){ - S3FS_PRN_DBG("There was no cache to truncate."); + if(TruncateCacheHasLock(true)){ + S3FS_PRN_DBG("Some expired caches have been truncated."); } S3FS_PRN_INFO3("add symbolic link cache entry[path=%s, value=%s]", key.c_str(), value.c_str());