13
13
// limitations under the License.
14
14
// -------------------------------------------------------------------------------------------------
15
15
16
- //! A common in-memory `Cache` for market and execution related data.
16
+ //! In-memory cache for market and execution data, with optional persistent backing.
17
+ //!
18
+ //! Provides methods to load, query, and update cached data such as instruments, orders, and prices.
17
19
18
- // Allow missing error docs for a large number of cache methods for now.
20
+ // Allow missing error documentation for now
19
21
#![ allow( clippy:: missing_errors_doc) ]
20
22
21
23
pub mod config;
@@ -99,8 +101,11 @@ impl Default for Cache {
99
101
}
100
102
101
103
impl Cache {
102
- /// Creates a new [`Cache`] instance.
104
+ /// Creates a new [`Cache`] instance with optional configuration and database adapter .
103
105
#[ must_use]
106
+ /// # Note
107
+ ///
108
+ /// Uses provided `CacheConfig` or defaults, and optional `CacheDatabaseAdapter` for persistence.
104
109
pub fn new (
105
110
config : Option < CacheConfig > ,
106
111
database : Option < Box < dyn CacheDatabaseAdapter > > ,
@@ -139,7 +144,7 @@ impl Cache {
139
144
140
145
// -- COMMANDS --------------------------------------------------------------------------------
141
146
142
- /// Clears the current general cache and loads the general objects from the cache database .
147
+ /// Clears and reloads general entries from the database into the cache.
143
148
///
144
149
/// # Errors
145
150
///
@@ -157,7 +162,7 @@ impl Cache {
157
162
Ok ( ( ) )
158
163
}
159
164
160
- /// Loads all caches (currencies, instruments, synthetics , accounts, orders, positions) from the database.
165
+ /// Loads all core caches (currencies, instruments, accounts, orders, positions) from the database.
161
166
///
162
167
/// # Errors
163
168
///
@@ -177,7 +182,7 @@ impl Cache {
177
182
Ok ( ( ) )
178
183
}
179
184
180
- /// Clears the current currencies cache and loads currencies from the cache database.
185
+ /// Clears and reloads the currency cache from the database.
181
186
///
182
187
/// # Errors
183
188
///
@@ -192,7 +197,7 @@ impl Cache {
192
197
Ok ( ( ) )
193
198
}
194
199
195
- /// Clears the current instruments cache and loads instruments from the cache database.
200
+ /// Clears and reloads the instrument cache from the database.
196
201
///
197
202
/// # Errors
198
203
///
@@ -207,8 +212,7 @@ impl Cache {
207
212
Ok ( ( ) )
208
213
}
209
214
210
- /// Clears the current synthetic instruments cache and loads synthetic instruments from the cache
211
- /// database.
215
+ /// Clears and reloads the synthetic instrument cache from the database.
212
216
///
213
217
/// # Errors
214
218
///
@@ -226,7 +230,7 @@ impl Cache {
226
230
Ok ( ( ) )
227
231
}
228
232
229
- /// Clears the current accounts cache and loads accounts from the cache database.
233
+ /// Clears and reloads the account cache from the database.
230
234
///
231
235
/// # Errors
232
236
///
@@ -244,7 +248,7 @@ impl Cache {
244
248
Ok ( ( ) )
245
249
}
246
250
247
- /// Clears the current orders cache and loads orders from the cache database.
251
+ /// Clears and reloads the order cache from the database.
248
252
///
249
253
/// # Errors
250
254
///
@@ -259,7 +263,7 @@ impl Cache {
259
263
Ok ( ( ) )
260
264
}
261
265
262
- /// Clears the current positions cache and loads positions from the cache database.
266
+ /// Clears and reloads the position cache from the database.
263
267
///
264
268
/// # Errors
265
269
///
@@ -1076,10 +1080,13 @@ impl Cache {
1076
1080
}
1077
1081
}
1078
1082
1079
- /// Adds a general object `value` (as bytes) to the cache at the given `key`.
1083
+ /// Adds a raw bytes entry to the cache under the given key.
1084
+ ///
1085
+ /// The cache stores only raw bytes; interpretation is the caller's responsibility.
1080
1086
///
1081
- /// The cache is agnostic to what the bytes actually represent (and how it may be serialized),
1082
- /// which provides maximum flexibility.
1087
+ /// # Errors
1088
+ ///
1089
+ /// Returns an error if persisting the entry to the backing database fails.
1083
1090
pub fn add ( & mut self , key : & str , value : Bytes ) -> anyhow:: Result < ( ) > {
1084
1091
check_valid_string ( key, stringify ! ( key) ) . expect ( FAILED ) ;
1085
1092
check_predicate_false ( value. is_empty ( ) , stringify ! ( value) ) . expect ( FAILED ) ;
@@ -1093,7 +1100,11 @@ impl Cache {
1093
1100
Ok ( ( ) )
1094
1101
}
1095
1102
1096
- /// Adds the given order `book` to the cache.
1103
+ /// Adds an `OrderBook` to the cache.
1104
+ ///
1105
+ /// # Errors
1106
+ ///
1107
+ /// Returns an error if persisting the order book to the backing database fails.
1097
1108
pub fn add_order_book ( & mut self , book : OrderBook ) -> anyhow:: Result < ( ) > {
1098
1109
log:: debug!( "Adding `OrderBook` {}" , book. instrument_id) ;
1099
1110
@@ -1107,7 +1118,11 @@ impl Cache {
1107
1118
Ok ( ( ) )
1108
1119
}
1109
1120
1110
- /// Adds the given `own_book` to the cache.
1121
+ /// Adds an `OwnOrderBook` to the cache.
1122
+ ///
1123
+ /// # Errors
1124
+ ///
1125
+ /// Returns an error if persisting the own order book fails.
1111
1126
pub fn add_own_order_book ( & mut self , own_book : OwnOrderBook ) -> anyhow:: Result < ( ) > {
1112
1127
log:: debug!( "Adding `OwnOrderBook` {}" , own_book. instrument_id) ;
1113
1128
0 commit comments