Skip to content

Commit 2c80e5e

Browse files
authored
Skip internal keys' lookup in LRU for the DefaultCache. (#1615)
Skip internal keys' lookup in LRU for the DefaultCache. Add test. Relates-To: DATASDK-71 Signed-off-by: Alexander Sopov <ext-alexander.sopov@here.com>
1 parent 76aaf4c commit 2c80e5e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,44 @@ 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+
const auto data_string{"this is key's data"};
999+
cache::CacheSettings settings;
1000+
settings.disk_path_mutable = cache_path_;
1001+
{
1002+
settings.eviction_policy = cache::EvictionPolicy::kNone;
1003+
DefaultCacheImplHelper cache(settings);
1004+
ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open());
1005+
cache.Clear();
1006+
1007+
constexpr auto expiry = 2;
1008+
EXPECT_TRUE(cache.Put(internal_key, data_string,
1009+
[data_string]() { return data_string; }, expiry));
1010+
}
1011+
1012+
settings.disk_path_mutable = cache_path_;
1013+
settings.disk_path_protected.reset();
1014+
settings.eviction_policy = cache::EvictionPolicy::kLeastRecentlyUsed;
1015+
1016+
DefaultCacheImplHelper cache(settings);
1017+
ASSERT_EQ(olp::cache::DefaultCache::Success, cache.Open());
1018+
1019+
auto stored_dats = cache.Get(internal_key);
1020+
ASSERT_TRUE(stored_dats);
1021+
1022+
std::string stored_string(
1023+
reinterpret_cast<const char*>(stored_dats->data()),
1024+
stored_dats->size());
1025+
EXPECT_EQ(stored_string, data_string);
1026+
1027+
cache.Clear();
1028+
}
1029+
}
1030+
9931031
TEST_F(DefaultCacheImplTest, ReadOnlyPartitionForProtectedCache) {
9941032
SCOPED_TRACE("Read only partition protected cache");
9951033
const std::string key{"somekey"};

0 commit comments

Comments
 (0)