From 2db0b664837c72a3eec6af0eda6f36f5f4da9399 Mon Sep 17 00:00:00 2001 From: Mykhailo Diachenko Date: Fri, 10 Oct 2025 14:08:35 +0300 Subject: [PATCH] Add method to list keys Adds interface for the method to list keys available in the cache. Relates-To: HERESDK-8383 Signed-off-by: Mykhailo Diachenko --- .../include/olp/core/cache/KeyValueCache.h | 14 ++++++++++++++ olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h b/olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h index 742f86749..8767be6fd 100644 --- a/olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h +++ b/olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h @@ -244,6 +244,20 @@ class CORE_API KeyValueCache { OLP_SDK_CORE_UNUSED(prefix); return client::ApiError(client::ErrorCode::Unknown, "Not implemented"); } + + /** + * @brief Lists the keys that match the given prefix. + * + * @param prefix The prefix that matches the keys. + * + * @return The collection of matched keys or an error. Empty collection if not + * keys match the prefix. + */ + virtual OperationOutcome ListKeysWithPrefix( + const std::string& prefix) { + OLP_SDK_CORE_UNUSED(prefix); + return client::ApiError(client::ErrorCode::Unknown, "Not implemented"); + } }; } // namespace cache diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp index f93399c72..a793e7f06 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp @@ -749,6 +749,16 @@ TEST(DefaultCacheTest, OpenTypeCache) { } } +TEST(DefaultCacheTest, ListKeysWithPrefixNotImplemented) { + olp::cache::DefaultCache cache; + + const auto result = cache.ListKeysWithPrefix("prefix"); + + EXPECT_FALSE(result.IsSuccessful()); + EXPECT_EQ(olp::client::ErrorCode::Unknown, result.GetError().GetErrorCode()); + EXPECT_EQ("Not implemented", result.GetError().GetMessage()); +} + struct TestParameters { OptionalString disk_path_mutable = kTempDirMutable; OptionalString disk_path_protected = olp::porting::none;