Skip to content

Commit 340a7ab

Browse files
authored
Modify documentation (core/include/cache) (#628)
Relates-to: OLPEDGE-860 Signed-off-by: Halyna Dumych <[email protected]>
1 parent d09f996 commit 340a7ab

File tree

3 files changed

+127
-83
lines changed

3 files changed

+127
-83
lines changed

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace olp {
2828
namespace cache {
2929

3030
/**
31-
* @brief Options for opening the disk cache.
31+
* @brief Options for opening a disk cache.
3232
*/
3333
enum OpenOptions : unsigned char {
3434
Default = 0x00, /*!< Opens the disk cache in the read-write mode. */
@@ -45,63 +45,74 @@ struct CacheSettings {
4545
*
4646
* If this parameter is not set, the downloaded data is stored
4747
* only in the in-memory cache that is limited by `#max_memory_cache_size`.
48+
*
4849
* @deprecated Use #disk_path_mutable instead.
4950
*/
5051
OLP_SDK_DEPRECATED("Use disk_path_mutable instead. Will be removed 03.2020")
5152
boost::optional<std::string> disk_path = boost::none;
5253

5354
/**
54-
* @brief The path to the mutable (read-write) on-disk cache where the
55-
* SDK will cache and lookup the content. You should have write permissions.
55+
* @brief The path to the mutable (read-write) on-disk cache where
56+
* the SDK caches and lookups the content.
57+
*
58+
* You should have write permissions.
5659
*
5760
* If this parameter is not set, the downloaded data is stored
5861
* only in the in-memory cache that is limited by `#max_memory_cache_size`.
5962
*/
6063
boost::optional<std::string> disk_path_mutable = boost::none;
6164

6265
/**
63-
* @brief Set the upper limit of disk space to use for persistent stores in
64-
* bytes. Default is 32 MB. Set it to std::uint64_t(-1) in order to never
65-
* evict data.
66+
* @brief Sets the upper limit (in bytes) of the disk space that is used for
67+
* persistent stores.
68+
*
69+
* The default value is 32 MB. To never evict data, set `max_disk_storage` to
70+
* `std::uint64_t(-1)`.
6671
*/
6772
std::uint64_t max_disk_storage = 1024ull * 1024ull * 32ull;
6873

6974
/**
70-
* @brief Set the upper limit of runtime memory to be used before being
71-
* written to disk in bytes. Default is 32 Mb.
75+
* @brief Sets the upper limit of the runtime memory (in bytes) before it is
76+
* written to the disk.
77+
*
78+
* The default value is 32 MB.
7279
*/
7380
size_t max_chunk_size = 1024u * 1024u * 32u;
7481

7582
/**
76-
* @brief Set the to indicate that continuous flushes to disk are
77-
* necessary to preserve maximum data between ignition cycles
83+
* @brief Sets the flag to indicate that continuous flushes to the disk are
84+
* necessary to preserve maximum data between the ignition cycles.
7885
*/
7986
bool enforce_immediate_flush = true;
8087

8188
/**
82-
* @brief Set the maximum permissable size of one file in storage in bytes.
83-
* Default is 2 MB.
89+
* @brief Sets the maximum permissible size of one file in the storage (in
90+
* bytes).
91+
*
92+
* The default value is 2 MB.
8493
*/
8594
size_t max_file_size = 1024u * 1024u * 2u;
8695

8796
/**
88-
* @brief Set the upper limit of the in-memory data cache size in bytes.
89-
* 0 means the in-memory cache is not used. Default is 1 MB.
97+
* @brief Sets the upper limit of the in-memory data cache size (in bytes).
98+
*
99+
* If set to `0`, the in-memory cache is not used. The default value is 1 MB.
90100
*/
91101
size_t max_memory_cache_size = 1024u * 1024u;
92102

93103
/**
94-
* @brief Set the disk cache open options.
104+
* @brief Sets the disk cache open options.
95105
*/
96106
OpenOptions openOptions = OpenOptions::Default;
97107

98108
/**
99-
* @brief Path to the protected (readonly) cache. This cache is used as a
100-
* primary cache for lookup. DefaultCache will open this cache in read-only
101-
* mode and will not write to it in case the disk_path_mutable is empty. This
102-
* path should only be used in case users would like to have a stable fallback
103-
* state or offline data that they can always access regardless of the network
104-
* state.
109+
* @brief The path to the protected (read-only) cache.
110+
*
111+
* This cache is used as a primary cache for lookup. `DefaultCache` opens this
112+
* cache in the read-only mode and does not write to it if
113+
* `disk_path_mutable` is empty. Use this cash if you want to have a stable
114+
* fallback state or offline data that you can always access regardless of
115+
* the network state.
105116
*/
106117
boost::optional<std::string> disk_path_protected = boost::none;
107118
};

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

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class DiskCache;
3333

3434
/**
3535
* @brief A default cache that provides an in-memory LRU cache and persistence
36-
* of the cached key-value pairs.
36+
* of cached key-value pairs.
3737
*
3838
* @note By default, the downloaded data is cached only in memory.
3939
* To enable the persistent cache, define
40-
* `olp::cache::CacheSettings::disk_path`. On iOS, the path is relative to the
41-
* application data folder.
40+
* `olp::cache::CacheSettings::disk_path`. On iOS, the path is relative to
41+
* the application data folder.
4242
*
4343
* The default maximum size of the persistent cache is 32 MB. If the entire
4444
* available disk space should be used, set
@@ -55,86 +55,98 @@ class CORE_API DefaultCache : public KeyValueCache {
5555
public:
5656
/*! The storage open result type */
5757
enum StorageOpenResult {
58-
Success, /*!< operation succeeded */
59-
OpenDiskPathFailure /*!< disk cache failure */
58+
Success, /*!< The operation succeeded. */
59+
OpenDiskPathFailure /*!< The disk cache failure. */
6060
};
6161

6262
/**
63-
* @brief Parameterized constructor.
64-
* @param settings Settings for the cache.
63+
* @brief Creates the `DefaultCache` instance.
64+
*
65+
* @param settings The cache settings.
6566
*/
6667
DefaultCache(const CacheSettings& settings = CacheSettings());
6768
~DefaultCache() override;
6869

6970
/**
70-
* @brief Opens the cache to start read/write operations.
71+
* @brief Opens the cache to start read and write operations.
7172
*
72-
* @return StorageOpenResult if there were problems opening any of the
73-
* provided pathes on the disk.
73+
* @return `StorageOpenResult` if there are problems opening any of
74+
* the provided paths on the disk.
7475
*/
7576
StorageOpenResult Open();
7677

7778
/**
78-
* @brief Closes the cache for use.
79+
* @brief Closes the cache.
7980
*/
8081
void Close();
8182

8283
/**
83-
* @brief Clears the contents of the cache.
84-
* @return Returns true if the operation is successfull, false otherwise.
84+
* @brief Clears the cache content.
85+
*
86+
* @return True if the operation is successful; false otherwise.
8587
*/
8688
bool Clear();
8789

8890
/**
89-
* @brief Stores the key-value pair into the cache.
90-
* @param key Key for this value
91-
* @param value The value of any type
92-
* @param encoder A method provided to encode the specified value into a
93-
* string
94-
* @param expiry Time in seconds to when pair will expire
95-
* @return Returns true if the operation is successfull, false otherwise.
91+
* @brief Stores the key-value pair in the cache.
92+
*
93+
* @param key The key for this value.
94+
* @param value The value of any type.
95+
* @param encoder Encodes the specified value into a string.
96+
* @param expiry The expiry time (in seconds) of the key-value pair.
97+
*
98+
* @return True if the operation is successful; false otherwise.
9699
*/
97100
bool Put(const std::string& key, const boost::any& value,
98101
const Encoder& encoder, time_t expiry) override;
99102

100103
/**
101-
* @brief Stores the raw binary data as value into the cache.
102-
* @param key Key for this value
103-
* @param value binary data to be stored
104-
* @param expiry Time in seconds to when pair will expire
105-
* @return Returns true if the operation is successfull, false otherwise.
104+
* @brief Stores the raw binary data as a value in the cache.
105+
*
106+
* @param key The key for this value.
107+
* @param value The binary data that should be stored.
108+
* @param expiry The expiry time (in seconds) of the key-value pair.
109+
*
110+
* @return True if the operation is successful; false otherwise.
106111
*/
107112
bool Put(const std::string& key, const KeyValueCache::ValueTypePtr value,
108113
time_t expiry) override;
109114

110115
/**
111116
* @brief Gets the key-value pair from the cache.
112-
* @param key Key to look for
113-
* @param decoder A method is provided to decode a value from a string if
114-
* needed
117+
*
118+
* @param key The key that is used to look for the key-value pair.
119+
* @param decoder Decodes the value from a string.
120+
*
121+
* @return The key-value pair.
115122
*/
116123
boost::any Get(const std::string& key, const Decoder& decoder) override;
117124

118125
/**
119126
* @brief Gets the key and binary data from the cache.
120-
* @param key Key to look for
127+
*
128+
* @param key The key that is used to look for the binary data.
129+
*
130+
* @return The key and binary data.
121131
*/
122132
KeyValueCache::ValueTypePtr Get(const std::string& key) override;
123133

124134
/**
125135
* @brief Removes the key-value pair from the cache.
126-
* @param key Key for the value to remove from cache
127136
*
128-
* @return Returns true if the operation is successfull, false otherwise.
137+
* @param key The key for the value.
138+
*
139+
* @return True if the operation is successful; false otherwise.
129140
*/
130141
bool Remove(const std::string& key) override;
131142

132143
/**
133-
* @brief Removes the values with the keys matching the given
144+
* @brief Removes the values with the keys that match the given
134145
* prefix from the cache.
135-
* @param prefix Prefix to look for
136146
*
137-
* @return Returns true on removal, false otherwise.
147+
* @param prefix The prefix that matches the keys.
148+
*
149+
* @return True if the values are removed; false otherwise.
138150
*/
139151
bool RemoveKeysWithPrefix(const std::string& prefix) override;
140152

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

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,68 +36,89 @@ using Encoder = std::function<std::string()>;
3636
using Decoder = std::function<boost::any(const std::string&)>;
3737

3838
/**
39-
* @brief Interface for cache expecting a key,value pair.
39+
* @brief An interface for a cache that expects a key-value pair.
4040
*/
4141
class CORE_API KeyValueCache {
4242
public:
43-
/// No expiry by default.
43+
/**
44+
* @brief The expiry time of the key-value pair.
45+
*
46+
* By default, the key-value pair has no expiry time.
47+
*/
4448
static constexpr time_t kDefaultExpiry = std::numeric_limits<time_t>::max();
45-
/// Value type to be stored in the DB.
49+
50+
/**
51+
* @brief The value type that is stored in the DB.
52+
*/
4653
using ValueType = std::vector<unsigned char>;
47-
/// Shared pointer type to the DB entry.
54+
55+
/**
56+
* @brief The shared pointer type of the DB entry.
57+
*/
4858
using ValueTypePtr = std::shared_ptr<ValueType>;
4959

5060
virtual ~KeyValueCache() = default;
5161

5262
/**
53-
* @brief Store key,value pair into the cache
54-
* @param key Key for this value
55-
* @param value The value of any type
56-
* @param encoder A method provided to encode the specified value into a
57-
* string
58-
* @param expiry Time in seconds to when pair will expire
59-
* @return Returns true if the operation is successfull, false otherwise.
63+
* @brief Stores the key-value pair in the cache.
64+
*
65+
* @param key The key for this value.
66+
* @param value The value of any type.
67+
* @param encoder Encodes the specified value into a string.
68+
* @param expiry The expiry time (in seconds) of the key-value pair.
69+
*
70+
* @return True if the operation is successful; false otherwise.
6071
*/
6172
virtual bool Put(const std::string& key, const boost::any& value,
6273
const Encoder& encoder, time_t expiry = kDefaultExpiry) = 0;
6374

6475
/**
65-
* @brief Store raw binary data as value into the cache
66-
* @param key Key for this value
67-
* @param value binary data to be stored
68-
* @param expiry Time in seconds to when pair will expire
69-
* @return Returns true if the operation is successfull, false otherwise.
76+
* @brief Stores the raw binary data as a value in the cache.
77+
*
78+
* @param key The key for this value.
79+
* @param value The binary data that should be stored.
80+
* @param expiry The expiry time (in seconds) of the key-value pair.
81+
*
82+
* @return True if the operation is successful; false otherwise.
7083
*/
7184
virtual bool Put(const std::string& key, const ValueTypePtr value,
7285
time_t expiry = kDefaultExpiry) = 0;
7386

7487
/**
75-
* @brief Get key,value pair from the cache
76-
* @param key Key to look for
77-
* @param decoder A method is provided to decode a value from a string if
78-
* needed
88+
* @brief Gets the key-value pair from the cache.
89+
*
90+
* @param key The key that is used to look for the key-value pair.
91+
* @param decoder Decodes the value from a string.
92+
*
93+
* @return The key-value pair.
7994
*/
8095
virtual boost::any Get(const std::string& key, const Decoder& encoder) = 0;
8196

8297
/**
83-
* @brief Get key and binary data from the cache
84-
* @param key Key to look for
98+
* @brief Gets the key and binary data from the cache.
99+
*
100+
* @param key The key that is used to look for the binary data.
101+
*
102+
* @return The key and binary data.
85103
*/
86104
virtual ValueTypePtr Get(const std::string& key) = 0;
87105

88106
/**
89-
* @brief Remove a key,value pair from the cache
90-
* @param key Key for the value to remove from cache
107+
* @brief Removes the key-value pair from the cache.
91108
*
92-
* @return Returns true if the operation is successfull, false otherwise.
109+
* @param key The key for the value.
110+
*
111+
* @return True if the operation is successful; false otherwise.
93112
*/
94113
virtual bool Remove(const std::string& key) = 0;
95114

96115
/**
97-
* @brief Remove values with keys matching the given prefix from the cache
98-
* @param prefix Prefix to look for
116+
* @brief Removes the values with the keys that match the given
117+
* prefix from the cache.
118+
*
119+
* @param prefix The prefix that matches the keys.
99120
*
100-
* @return Returns true on removal, false otherwise.
121+
* @return True if the values are removed; false otherwise.
101122
*/
102123
virtual bool RemoveKeysWithPrefix(const std::string& prefix) = 0;
103124
};

0 commit comments

Comments
 (0)