tangled
alpha
login
or
join now
nonbinary.computer
/
jacquard
80
fork
atom
A better Rust ATProto crate
80
fork
atom
overview
issues
9
pulls
pipelines
resolver cache tunables
Orual
4 months ago
e3b48af3
cfedbbd0
0/1
build.yml
failed
2min 32s
+92
-10
1 changed file
expand all
collapse all
unified
split
crates
jacquard-identity
src
lib.rs
+92
-10
crates/jacquard-identity/src/lib.rs
···
110
110
))]
111
111
use std::sync::Arc;
112
112
113
113
+
/// Configuration for resolver caching
114
114
+
#[cfg(feature = "cache")]
115
115
+
#[derive(Clone, Debug)]
116
116
+
pub struct CacheConfig {
117
117
+
/// Maximum capacity for handle→DID cache
118
118
+
pub handle_to_did_capacity: u64,
119
119
+
/// TTL for handle→DID cache
120
120
+
pub handle_to_did_ttl: Duration,
121
121
+
/// Maximum capacity for DID→document cache
122
122
+
pub did_to_doc_capacity: u64,
123
123
+
/// TTL for DID→document cache
124
124
+
pub did_to_doc_ttl: Duration,
125
125
+
/// Maximum capacity for authority→DID cache
126
126
+
pub authority_to_did_capacity: u64,
127
127
+
/// TTL for authority→DID cache
128
128
+
pub authority_to_did_ttl: Duration,
129
129
+
/// Maximum capacity for NSID→schema cache
130
130
+
pub nsid_to_schema_capacity: u64,
131
131
+
/// TTL for NSID→schema cache
132
132
+
pub nsid_to_schema_ttl: Duration,
133
133
+
}
134
134
+
135
135
+
#[cfg(feature = "cache")]
136
136
+
impl Default for CacheConfig {
137
137
+
fn default() -> Self {
138
138
+
Self {
139
139
+
handle_to_did_capacity: 2000,
140
140
+
handle_to_did_ttl: Duration::from_secs(24 * 3600),
141
141
+
did_to_doc_capacity: 1000,
142
142
+
did_to_doc_ttl: Duration::from_secs(72 * 3600),
143
143
+
authority_to_did_capacity: 1000,
144
144
+
authority_to_did_ttl: Duration::from_secs(168 * 3600),
145
145
+
nsid_to_schema_capacity: 1000,
146
146
+
nsid_to_schema_ttl: Duration::from_secs(168 * 3600),
147
147
+
}
148
148
+
}
149
149
+
}
150
150
+
151
151
+
#[cfg(feature = "cache")]
152
152
+
impl CacheConfig {
153
153
+
/// Set handle→DID cache parameters
154
154
+
pub fn with_handle_cache(mut self, capacity: u64, ttl: Duration) -> Self {
155
155
+
self.handle_to_did_capacity = capacity;
156
156
+
self.handle_to_did_ttl = ttl;
157
157
+
self
158
158
+
}
159
159
+
160
160
+
/// Set DID→document cache parameters
161
161
+
pub fn with_did_doc_cache(mut self, capacity: u64, ttl: Duration) -> Self {
162
162
+
self.did_to_doc_capacity = capacity;
163
163
+
self.did_to_doc_ttl = ttl;
164
164
+
self
165
165
+
}
166
166
+
167
167
+
/// Set authority→DID cache parameters
168
168
+
pub fn with_authority_cache(mut self, capacity: u64, ttl: Duration) -> Self {
169
169
+
self.authority_to_did_capacity = capacity;
170
170
+
self.authority_to_did_ttl = ttl;
171
171
+
self
172
172
+
}
173
173
+
174
174
+
/// Set NSID→schema cache parameters
175
175
+
pub fn with_schema_cache(mut self, capacity: u64, ttl: Duration) -> Self {
176
176
+
self.nsid_to_schema_capacity = capacity;
177
177
+
self.nsid_to_schema_ttl = ttl;
178
178
+
self
179
179
+
}
180
180
+
}
181
181
+
113
182
/// Cache layer for resolver operations
114
183
#[cfg(feature = "cache")]
115
184
#[derive(Clone)]
···
122
191
123
192
#[cfg(feature = "cache")]
124
193
impl ResolverCaches {
125
125
-
fn new() -> Self {
194
194
+
fn new(config: &CacheConfig) -> Self {
126
195
Self {
127
196
handle_to_did: Cache::builder()
128
128
-
.max_capacity(2000)
129
129
-
.time_to_live(Duration::from_secs(24 * 3600))
197
197
+
.max_capacity(config.handle_to_did_capacity)
198
198
+
.time_to_live(config.handle_to_did_ttl)
130
199
.build(),
131
200
did_to_doc: Cache::builder()
132
132
-
.max_capacity(1000)
133
133
-
.time_to_live(Duration::from_secs(72 * 3600))
201
201
+
.max_capacity(config.did_to_doc_capacity)
202
202
+
.time_to_live(config.did_to_doc_ttl)
134
203
.build(),
135
204
authority_to_did: Cache::builder()
136
136
-
.max_capacity(200)
137
137
-
.time_to_live(Duration::from_secs(168 * 3600))
205
205
+
.max_capacity(config.authority_to_did_capacity)
206
206
+
.time_to_live(config.authority_to_did_ttl)
138
207
.build(),
139
208
nsid_to_schema: Cache::builder()
140
140
-
.max_capacity(500)
141
141
-
.time_to_live(Duration::from_secs(168 * 3600))
209
209
+
.max_capacity(config.nsid_to_schema_capacity)
210
210
+
.time_to_live(config.nsid_to_schema_ttl)
142
211
.build(),
143
212
}
213
213
+
}
214
214
+
}
215
215
+
216
216
+
impl Default for ResolverCaches {
217
217
+
fn default() -> Self {
218
218
+
Self::new(&CacheConfig::default())
144
219
}
145
220
}
146
221
···
222
297
#[cfg(feature = "cache")]
223
298
/// Enable caching with default configuration
224
299
pub fn with_cache(mut self) -> Self {
225
225
-
self.caches = Some(ResolverCaches::new());
300
300
+
self.caches = Some(ResolverCaches::default());
301
301
+
self
302
302
+
}
303
303
+
304
304
+
#[cfg(feature = "cache")]
305
305
+
/// Enable caching with custom configuration
306
306
+
pub fn with_cache_config(mut self, config: CacheConfig) -> Self {
307
307
+
self.caches = Some(ResolverCaches::new(&config));
226
308
self
227
309
}
228
310