Skip to content

Commit 3db5c8c

Browse files
Align cache according to requirements.
If the user do not provide a default cache, SDK will create a default one. Remove CreateDefaultCache from CatalogClient.h Changed CatalogClientImpl class constructor to take settings by value. Resolves: OLPEDGE-872 Resolves: OLPEDGE-908 Signed-off-by: Mykhailo Kuchma <[email protected]> Signed-off-by: Diachenko Mykahilo <[email protected]>
1 parent 05d39a4 commit 3db5c8c

File tree

8 files changed

+33
-39
lines changed

8 files changed

+33
-39
lines changed

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/CatalogClient.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@ namespace model {
4949
class Partition;
5050
} // namespace model
5151

52-
/**
53-
* @brief Creates an instance of the default cache with provided settings.
54-
* @param settings Cache settings.
55-
*
56-
* @return DefaultCache instance.
57-
*/
58-
DATASERVICE_READ_API std::shared_ptr<cache::KeyValueCache> CreateDefaultCache(
59-
const cache::CacheSettings& settings = cache::CacheSettings());
60-
6152
class CatalogRequest;
6253
using CatalogResult = model::Catalog;
6354
using CatalogResponse = client::ApiResponse<CatalogResult, client::ApiError>;

olp-cpp-sdk-dataservice-read/src/CatalogClient.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,24 @@
1818
*/
1919

2020
#include "olp/dataservice/read/CatalogClient.h"
21-
#include <olp/core/cache/DefaultCache.h>
21+
22+
#include "olp/core/cache/DefaultCache.h"
23+
#include "olp/core/client/OlpClientSettingsFactory.h"
2224
#include "CatalogClientImpl.h"
2325

2426
namespace olp {
2527
namespace dataservice {
2628
namespace read {
2729

28-
std::shared_ptr<cache::KeyValueCache> CreateDefaultCache(
29-
const cache::CacheSettings& settings) {
30-
auto cache = std::make_shared<cache::DefaultCache>(settings);
31-
cache->Open();
32-
return std::move(cache);
33-
}
34-
3530
CatalogClient::CatalogClient(client::HRN catalog,
3631
client::OlpClientSettings settings) {
37-
auto cache = settings.cache;
38-
auto settings_ptr =
39-
std::make_shared<client::OlpClientSettings>(std::move(settings));
40-
impl_ = std::make_shared<CatalogClientImpl>(
41-
std::move(catalog), std::move(settings_ptr), std::move(cache));
32+
// If the user did not specify cache, we creade a default one (memory only)
33+
if (!settings.cache) {
34+
settings.cache = client::OlpClientSettingsFactory::CreateDefaultCache({});
35+
}
36+
37+
impl_ = std::make_shared<CatalogClientImpl>(std::move(catalog),
38+
std::move(settings));
4239
}
4340

4441
bool CatalogClient::cancelPendingRequests() {

olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
#include "CatalogClientImpl.h"
2121

22-
#include <olp/core/client/OlpClientFactory.h>
2322
#include <olp/core/logging/Log.h>
24-
2523
#include "PendingRequests.h"
2624
#include "PrefetchTilesProvider.h"
2725
#include "repositories/ApiRepository.h"
@@ -40,12 +38,11 @@ namespace {
4038
constexpr auto kLogTag = "CatalogClientImpl";
4139
}
4240

43-
CatalogClientImpl::CatalogClientImpl(
44-
HRN hrn, std::shared_ptr<OlpClientSettings> settings,
45-
std::shared_ptr<cache::KeyValueCache> cache)
46-
: catalog_(std::move(hrn)),
47-
settings_(settings),
48-
api_client_(OlpClientFactory::Create(*settings)) {
41+
CatalogClientImpl::CatalogClientImpl(HRN catalog, OlpClientSettings settings)
42+
: catalog_(std::move(catalog)),
43+
settings_(std::make_shared<OlpClientSettings>(std::move(settings))) {
44+
auto cache = settings_->cache;
45+
4946
// create repositories, satisfying dependencies.
5047
auto api_repo = std::make_shared<ApiRepository>(catalog_, settings_, cache);
5148

@@ -59,7 +56,7 @@ CatalogClientImpl::CatalogClientImpl(
5956
catalog_, api_repo, catalog_repo_, partition_repo_, cache);
6057

6158
auto prefetch_repo = std::make_shared<PrefetchTilesRepository>(
62-
hrn, api_repo, partition_repo_->GetPartitionsCacheRepository(),
59+
catalog_, api_repo, partition_repo_->GetPartitionsCacheRepository(),
6360
settings_);
6461

6562
prefetch_provider_ = std::make_shared<PrefetchTilesProvider>(

olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ class PendingRequests;
5050

5151
class CatalogClientImpl final {
5252
public:
53-
CatalogClientImpl(client::HRN catalog,
54-
std::shared_ptr<client::OlpClientSettings> settings,
55-
std::shared_ptr<cache::KeyValueCache> cache);
53+
CatalogClientImpl(client::HRN catalog, client::OlpClientSettings settings);
5654

5755
~CatalogClientImpl();
5856

@@ -93,7 +91,6 @@ class CatalogClientImpl final {
9391
private:
9492
client::HRN catalog_;
9593
std::shared_ptr<client::OlpClientSettings> settings_;
96-
std::shared_ptr<client::OlpClient> api_client_;
9794
std::shared_ptr<repository::CatalogRepository> catalog_repo_;
9895
std::shared_ptr<repository::PartitionsRepository> partition_repo_;
9996
std::shared_ptr<repository::DataRepository> data_repo_;

olp-cpp-sdk-dataservice-read/tests/DataRepositoryTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
#include <matchers/NetworkUrlMatchers.h>
2323
#include <mocks/NetworkMock.h>
24+
#include <olp/core/cache/KeyValueCache.h>
2425
#include <olp/core/client/OlpClientFactory.h>
2526
#include <olp/core/client/OlpClientSettings.h>
27+
#include <olp/core/client/OlpClientSettingsFactory.h>
2628
#include <olp/dataservice/read/DataRequest.h>
2729
#include <repositories/DataRepository.h>
2830

@@ -62,7 +64,8 @@ class DataRepositoryTest : public ::testing::Test {
6264
void DataRepositoryTest::SetUp() {
6365
network_mock_ = std::make_shared<NetworkMock>();
6466
settings_ = std::make_shared<olp::client::OlpClientSettings>();
65-
settings_->cache = olp::dataservice::read::CreateDefaultCache();
67+
settings_->cache =
68+
olp::client::OlpClientSettingsFactory::CreateDefaultCache({});
6669
settings_->network_request_handler = network_mock_;
6770
}
6871

tests/integration/olp-cpp-sdk-dataservice-read/CatalogClientCacheTest.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class CatalogClientCacheTest : public CatalogClientTestBase {
5454
ClearCache(settings.disk_path.get());
5555
break;
5656
}
57+
case CacheType::NONE: {
58+
// We don't create a cache here
59+
settings_.cache = nullptr;
60+
return;
61+
}
5762
default:
5863
// shouldn't get here
5964
break;
@@ -435,5 +440,6 @@ TEST_P(CatalogClientCacheTest, GetVolatilePartitionsExpiry) {
435440

436441
INSTANTIATE_TEST_SUITE_P(, CatalogClientCacheTest,
437442
::testing::Values(CacheType::IN_MEMORY,
438-
CacheType::DISK, CacheType::BOTH));
443+
CacheType::DISK, CacheType::BOTH,
444+
CacheType::NONE));
439445
} // namespace

tests/integration/olp-cpp-sdk-dataservice-read/CatalogClientTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include <gmock/gmock.h>
2121
#include <matchers/NetworkUrlMatchers.h>
2222
#include <mocks/NetworkMock.h>
23+
#include <olp/core/cache/KeyValueCache.h>
2324
#include <olp/core/client/HRN.h>
25+
#include <olp/core/client/OlpClientSettingsFactory.h>
2426
#include <olp/core/http/Network.h>
2527
#include <olp/core/logging/Log.h>
2628
#include <olp/core/porting/make_unique.h>
@@ -1032,7 +1034,8 @@ TEST_P(CatalogClientTest, GetDataWithPartitionIdCancelInnerConfig) {
10321034

10331035
olp::cache::CacheSettings cache_settings;
10341036
cache_settings.max_memory_cache_size = 0;
1035-
settings_.cache = olp::dataservice::read::CreateDefaultCache(cache_settings);
1037+
settings_.cache =
1038+
olp::client::OlpClientSettingsFactory::CreateDefaultCache(cache_settings);
10361039
auto catalog_client =
10371040
std::make_unique<olp::dataservice::read::CatalogClient>(hrn, settings_);
10381041

tests/integration/olp-cpp-sdk-dataservice-read/CatalogClientTestBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace olp {
2929
namespace tests {
3030
namespace integration {
3131

32-
enum class CacheType { IN_MEMORY, DISK, BOTH };
32+
enum class CacheType { IN_MEMORY, DISK, BOTH, NONE };
3333

3434
std::ostream& operator<<(std::ostream& os, const CacheType cache_type);
3535

0 commit comments

Comments
 (0)