Skip to content

Commit a55e373

Browse files
committed
Skip internal keys' lookup in LRU
for the DefaultCache. Relates-To: DATASDK-71 Signed-off-by: sopov <[email protected]>
1 parent 478cb38 commit a55e373

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ OperationOutcomeEmpty DefaultCacheImpl::GetFromDiskCache(
881881

882882
if (expiry > 0 || protected_keys_.IsProtected(key)) {
883883
// Entry didn't expire yet, we can still use it
884-
if (!PromoteKeyLru(key)) {
884+
if (!IsInternalKey(key) && !PromoteKeyLru(key)) {
885885
// If not found in LRU or not protected no need to look in disk cache
886886
// either.
887887
OLP_SDK_LOG_DEBUG_F(kLogTag,

olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,38 @@ TEST_F(DefaultCacheImplTest, LruCacheEvictionWithProtected) {
990990
}
991991
}
992992

993+
TEST_F(DefaultCacheImplTest, InternalKeysBypassLru) {
994+
{
995+
SCOPED_TRACE("Protect and release keys, which suppose to be evicted");
996+
997+
const auto internal_key{"internal::protected::protected_data"};
998+
cache::CacheSettings settings;
999+
settings.disk_path_mutable = cache_path_;
1000+
settings.max_disk_storage = 2u * 1024u * 1024u;
1001+
{
1002+
DefaultCacheImplHelper cache(settings);
1003+
ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open());
1004+
cache.Clear();
1005+
const std::string key{"somekey"};
1006+
std::string data_string{"this is key's data"};
1007+
1008+
constexpr auto expiry = 2;
1009+
EXPECT_TRUE(cache.Put(key, data_string,
1010+
[data_string]() { return data_string; }, expiry));
1011+
ASSERT_TRUE(cache.Protect({key}));
1012+
}
1013+
1014+
settings.disk_path_mutable = cache_path_;
1015+
settings.disk_path_protected.reset();
1016+
1017+
DefaultCacheImplHelper cache(settings);
1018+
ASSERT_TRUE(cache.Open());
1019+
// no keys was evicted
1020+
EXPECT_TRUE(cache.Get(internal_key));
1021+
cache.Clear();
1022+
}
1023+
}
1024+
9931025
TEST_F(DefaultCacheImplTest, ReadOnlyPartitionForProtectedCache) {
9941026
SCOPED_TRACE("Read only partition protected cache");
9951027
const std::string key{"somekey"};

0 commit comments

Comments
 (0)