diff --git a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp index 1c53c4457..2922d86ab 100644 --- a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp +++ b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp @@ -881,7 +881,7 @@ OperationOutcomeEmpty DefaultCacheImpl::GetFromDiskCache( if (expiry > 0 || protected_keys_.IsProtected(key)) { // Entry didn't expire yet, we can still use it - if (!PromoteKeyLru(key)) { + if (!IsInternalKey(key) && !PromoteKeyLru(key)) { // If not found in LRU or not protected no need to look in disk cache // either. OLP_SDK_LOG_DEBUG_F(kLogTag, diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index 338489678..e78454d87 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -990,6 +990,44 @@ TEST_F(DefaultCacheImplTest, LruCacheEvictionWithProtected) { } } +TEST_F(DefaultCacheImplTest, InternalKeysBypassLru) { + { + SCOPED_TRACE("Protect and release keys, which suppose to be evicted"); + + const auto internal_key{"internal::protected::protected_data"}; + const auto data_string{"this is key's data"}; + cache::CacheSettings settings; + settings.disk_path_mutable = cache_path_; + { + settings.eviction_policy = cache::EvictionPolicy::kNone; + DefaultCacheImplHelper cache(settings); + ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open()); + cache.Clear(); + + constexpr auto expiry = 2; + EXPECT_TRUE(cache.Put(internal_key, data_string, + [data_string]() { return data_string; }, expiry)); + } + + settings.disk_path_mutable = cache_path_; + settings.disk_path_protected.reset(); + settings.eviction_policy = cache::EvictionPolicy::kLeastRecentlyUsed; + + DefaultCacheImplHelper cache(settings); + ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open()); + + auto stored_dats = cache.Get(internal_key); + ASSERT_TRUE(stored_dats); + + std::string stored_string( + reinterpret_cast(stored_dats->data()), + stored_dats->size()); + EXPECT_EQ(stored_string, data_string); + + cache.Clear(); + } +} + TEST_F(DefaultCacheImplTest, ReadOnlyPartitionForProtectedCache) { SCOPED_TRACE("Read only partition protected cache"); const std::string key{"somekey"};