aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index de5bccc3a..cf066fb0e 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -249,11 +249,9 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const IoHash& HashKey, const
{
RwLock::SharedLockScope _(m_Lock);
- auto it = m_Buckets.find(std::string(InBucket));
-
- if (it != m_Buckets.end())
+ if (auto It = m_Buckets.find(std::string(InBucket)); It != m_Buckets.end())
{
- Bucket = &it->second;
+ Bucket = &It->second;
}
}
@@ -263,7 +261,14 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const IoHash& HashKey, const
RwLock::ExclusiveLockScope _(m_Lock);
- Bucket = &m_Buckets[std::string(InBucket)];
+ if (auto It = m_Buckets.find(std::string(InBucket)); It != m_Buckets.end())
+ {
+ Bucket = &It->second;
+ }
+ else
+ {
+ Bucket = &m_Buckets[std::string(InBucket)];
+ }
}
// Note that since the underlying IoBuffer is retained, the content type is also
@@ -757,7 +762,7 @@ ZenCacheDiskLayer::CacheBucket::GatherReferences(GcContext& GcCtx)
const GcClock::Tick ExpireTicks = ExpireTime.time_since_epoch().count();
- RwLock::ExclusiveLockScope _(m_IndexLock);
+ RwLock::SharedLockScope _(m_IndexLock);
std::vector<IoHash> ValidKeys;
std::vector<IoHash> ExpiredKeys;
@@ -773,7 +778,7 @@ ZenCacheDiskLayer::CacheBucket::GatherReferences(GcContext& GcCtx)
return Entry.LastAccess < Ticks;
});
- Cids.reserve(Entries.size());
+ Cids.reserve(1024);
for (auto Kv = ValidIt; Kv != Entries.end(); ++Kv)
{
@@ -791,10 +796,13 @@ ZenCacheDiskLayer::CacheBucket::GatherReferences(GcContext& GcCtx)
if (CacheValue.Value)
{
ZEN_ASSERT(CacheValue.Value.GetContentType() == ZenContentType::kCbObject);
-
+ if (Cids.size() > 1024)
+ {
+ GcCtx.ContributeCids(Cids);
+ Cids.clear();
+ }
CbObject Obj(SharedBuffer{CacheValue.Value});
Obj.IterateAttachments([&Cids](CbFieldView Field) { Cids.push_back(Field.AsAttachment()); });
- GcCtx.ContributeCids(Cids);
}
}
}