fast_cache/storage/embedded_store_sharded/
write.rs1use super::*;
2
3impl WorkerLocalEmbeddedStore {
4 pub fn set(&mut self, key: Bytes, value: Bytes, ttl_ms: Option<u64>) {
5 self.set_if_local(key, value, ttl_ms)
6 .expect("worker-local embedded store key does not belong to this thread");
7 }
8
9 pub fn set_slice_no_ttl(&mut self, key: &[u8], value: &[u8]) {
10 self.set_slice_no_ttl_if_local(key, value)
11 .expect("worker-local embedded store key does not belong to this thread");
12 }
13
14 #[inline(always)]
15 pub fn set_slice_routed_no_ttl_local(
16 &mut self,
17 route: EmbeddedKeyRoute,
18 key: &[u8],
19 value: &[u8],
20 ) {
21 debug_assert!(self.owns_shard(route.shard_id));
22 self.inner.local_set_slice_no_ttl(route, key, value);
23 }
24
25 #[inline(always)]
26 pub fn set_slice_routed_local(
27 &mut self,
28 route: EmbeddedKeyRoute,
29 key: &[u8],
30 value: &[u8],
31 ttl_ms: Option<u64>,
32 ) {
33 debug_assert!(self.owns_shard(route.shard_id));
34 self.inner.local_set_slice(route, key, value, ttl_ms);
35 }
36
37 #[inline(always)]
38 pub fn set_prepared_point_slice_no_ttl_local(
39 &mut self,
40 prepared: &PreparedPointKey,
41 value: &[u8],
42 ) {
43 debug_assert!(self.owns_shard(prepared.route().shard_id));
44 self.inner.local_set_prepared_slice_no_ttl(prepared, value);
45 }
46
47 pub fn set_slice_no_ttl_if_local(
48 &mut self,
49 key: &[u8],
50 value: &[u8],
51 ) -> Result<(), LocalRouteError> {
52 let route = self.local_key_route(key)?;
53 self.inner.local_set_slice_no_ttl(route, key, value);
54 Ok(())
55 }
56
57 #[inline(always)]
58 pub fn set_slice_routed_no_ttl_if_local(
59 &mut self,
60 route: EmbeddedKeyRoute,
61 key: &[u8],
62 value: &[u8],
63 ) -> Result<(), LocalRouteError> {
64 self.ensure_local_route(route)?;
65 self.inner.local_set_slice_no_ttl(route, key, value);
66 Ok(())
67 }
68
69 pub fn set_if_local(
70 &mut self,
71 key: Bytes,
72 value: Bytes,
73 ttl_ms: Option<u64>,
74 ) -> Result<(), LocalRouteError> {
75 self.local_key_route(&key)?;
76 self.inner.local_set(key, value, ttl_ms);
77 Ok(())
78 }
79
80 pub fn batch_set(&mut self, items: Vec<(Bytes, Bytes)>, ttl_ms: Option<u64>) {
81 self.batch_set_if_local(items, ttl_ms)
82 .expect("worker-local embedded store batch includes keys owned by another thread");
83 }
84
85 pub fn batch_set_if_local(
86 &mut self,
87 items: Vec<(Bytes, Bytes)>,
88 ttl_ms: Option<u64>,
89 ) -> Result<(), LocalRouteError> {
90 for (key, _) in &items {
91 self.local_key_route(key)?;
92 }
93 self.inner.local_batch_set(items, ttl_ms);
94 Ok(())
95 }
96
97 pub fn batch_set_session_owned_no_ttl(
98 &mut self,
99 session_prefix: Bytes,
100 items: Vec<(Bytes, Bytes)>,
101 ) {
102 self.batch_set_session_owned_no_ttl_if_local(session_prefix, items)
103 .expect("worker-local embedded store session does not belong to this thread");
104 }
105
106 pub fn batch_set_session_owned_no_ttl_if_local(
107 &mut self,
108 session_prefix: Bytes,
109 items: Vec<(Bytes, Bytes)>,
110 ) -> Result<(), LocalRouteError> {
111 self.local_session_route(&session_prefix)?;
112 self.inner
113 .local_batch_set_session_owned_no_ttl(session_prefix, items);
114 Ok(())
115 }
116
117 pub fn batch_set_session_packed_no_ttl(&mut self, packed: PackedSessionWrite) {
118 self.batch_set_session_packed_no_ttl_if_local(packed)
119 .expect("worker-local embedded store session does not belong to this thread");
120 }
121
122 pub fn batch_set_session_packed_no_ttl_if_local(
123 &mut self,
124 packed: PackedSessionWrite,
125 ) -> Result<(), LocalRouteError> {
126 self.local_session_route(packed.session_prefix())?;
127 self.inner.local_batch_set_session_packed_no_ttl(packed);
128 Ok(())
129 }
130}