Skip to content

Commit fbe2a1f

Browse files
Changes DefaultCache constructor to take settings by value. (#625)
Additionally makes constructor explicit. It is not a good practice to take hide move oportunities from API users. Making the DefaultCache constructor and the OlpClientSettingsFactory::CreateDefaultCache() method take-in the CacheSettings by copy will allow user to pass-move and save possible copies on the strings. This also deprecates the olp::dataservice::write::StreamLayerClient CreateDefaultCache() function as it is a duplicate to the OlpClientSettingsFactory::CreateDefaultCache() method. Will be removed by 06.2020. Until then this free function will use OlpClientSettingsFactory internally to create the default cache instance. Resolves: OLPEDGE-1509 Signed-off-by: Mykhailo Kuchma <[email protected]> Signed-off-by: Andrei Popescu <[email protected]>
1 parent 6f4f61a commit fbe2a1f

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CORE_API DefaultCache : public KeyValueCache {
6464
*
6565
* @param settings The cache settings.
6666
*/
67-
DefaultCache(const CacheSettings& settings = CacheSettings());
67+
explicit DefaultCache(CacheSettings settings = {});
6868
~DefaultCache() override;
6969

7070
/**

olp-cpp-sdk-core/include/olp/core/client/OlpClientSettingsFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CORE_API OlpClientSettingsFactory final {
8989
* @return The `KeyValueCache` instance.
9090
*/
9191
static std::unique_ptr<cache::KeyValueCache> CreateDefaultCache(
92-
const cache::CacheSettings& settings);
92+
cache::CacheSettings settings);
9393
};
9494

9595
} // namespace client

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ bool StoreExpiry(const std::string& key, olp::cache::DiskCache& disk_cache,
6565
namespace olp {
6666
namespace cache {
6767

68-
DefaultCache::DefaultCache(const CacheSettings& settings)
69-
: settings_(settings),
68+
DefaultCache::DefaultCache(CacheSettings settings)
69+
: settings_(std::move(settings)),
7070
is_open_(false),
7171
memory_cache_(nullptr),
7272
mutable_cache_(nullptr),

olp-cpp-sdk-core/src/client/OlpClientSettingsFactory.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ OlpClientSettingsFactory::CreateDefaultNetworkRequestHandler(
4040
}
4141

4242
std::unique_ptr<cache::KeyValueCache>
43-
OlpClientSettingsFactory::CreateDefaultCache(
44-
const cache::CacheSettings& settings) {
45-
auto cache = std::make_unique<cache::DefaultCache>(settings);
43+
OlpClientSettingsFactory::CreateDefaultCache(cache::CacheSettings settings) {
44+
auto cache = std::make_unique<cache::DefaultCache>(std::move(settings));
4645
cache->Open();
4746
return std::move(cache);
4847
}

olp-cpp-sdk-dataservice-write/include/olp/dataservice/write/StreamLayerClient.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <olp/core/client/ApiError.h>
2525
#include <olp/core/client/ApiResponse.h>
2626
#include <olp/core/client/OlpClientSettings.h>
27+
#include <olp/core/porting/deprecated.h>
2728
#include <olp/dataservice/write/DataServiceWriteApi.h>
2829
#include <olp/dataservice/write/StreamLayerClientSettings.h>
2930
#include <olp/dataservice/write/generated/model/ResponseOk.h>
@@ -46,9 +47,14 @@ class StreamLayerClientImpl;
4647
* @brief Creates an instance of the default cache with the provided settings.
4748
* @param settings Cache settings.
4849
* @return DefaultCache instance.
50+
* @deprecated Use olp::client::OlpClientSettingsFactory::CreateDefaultCache()
51+
* instead. Will be remove by 06.2020.
4952
*/
53+
OLP_SDK_DEPRECATED(
54+
"Please use OlpClientSettingsFactory::CreateDefaultCache() instead. "
55+
"Will be removed by 06.2020")
5056
std::shared_ptr<cache::KeyValueCache> CreateDefaultCache(
51-
const cache::CacheSettings& settings = cache::CacheSettings());
57+
cache::CacheSettings settings = {});
5258

5359
using PublishDataResult = olp::dataservice::write::model::ResponseOkSingle;
5460
using PublishDataResponse =
@@ -68,7 +74,8 @@ class DATASERVICE_WRITE_API StreamLayerClient {
6874

6975
/**
7076
* @brief StreamLayerClient Constructor.
71-
* @param catalog OLP HRN that specifies the catalog to which this client writes.
77+
* @param catalog OLP HRN that specifies the catalog to which this client
78+
* writes.
7279
* @param client_settings \c StreamLayerClient settings used to control
7380
* the behaviour of flush mechanism and other StreamLayerClient specific
7481
* properties.
@@ -149,8 +156,8 @@ class DATASERVICE_WRITE_API StreamLayerClient {
149156

150157
/**
151158
* @brief Sends a list of SDII messages to an OLP stream layer.
152-
* The SDII message data must be in the SDII MessageList protobuf format. For more
153-
* information, please see the OLP Sensor Data Ingestion Interface
159+
* The SDII message data must be in the SDII MessageList protobuf format. For
160+
* more information, please see the OLP Sensor Data Ingestion Interface
154161
* documentation and schemas.
155162
* @param request PublishSdiiRequest object that represents the parameters for
156163
* this PublishSdii call.
@@ -161,8 +168,8 @@ class DATASERVICE_WRITE_API StreamLayerClient {
161168

162169
/**
163170
* @brief Sends a list of SDII messages to an OLP stream layer.
164-
* The SDII message data must be in the SDII MessageList protobuf format. For more
165-
* information, please see the OLP Sensor Data Ingestion Interface
171+
* The SDII message data must be in the SDII MessageList protobuf format. For
172+
* more information, please see the OLP Sensor Data Ingestion Interface
166173
* documentation and schemas.
167174
* @param request PublishSdiiRequest object that represents the parameters for
168175
* this PublishSdii call.

olp-cpp-sdk-dataservice-write/src/StreamLayerClient.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ namespace dataservice {
2828
namespace write {
2929

3030
std::shared_ptr<cache::KeyValueCache> CreateDefaultCache(
31-
const cache::CacheSettings& settings) {
32-
auto cache = std::make_shared<cache::DefaultCache>(settings);
33-
cache->Open();
34-
return std::move(cache);
31+
cache::CacheSettings settings) {
32+
return client::OlpClientSettingsFactory::CreateDefaultCache(
33+
std::move(settings));
3534
}
3635

3736
StreamLayerClient::StreamLayerClient(client::HRN catalog,

0 commit comments

Comments
 (0)