MCPcopy Create free account
hub / github.com/LEXUGE/dcompass / put

Method put

droute/src/cache.rs:122–146  ·  view source on GitHub ↗
(&self, tag: Label, query: &Message<Bytes>, msg: Message<Bytes>)

Source from the content-addressed store, hash-verified

120 }
121
122 pub fn put(&self, tag: Label, query: &Message<Bytes>, msg: Message<Bytes>) {
123 if msg.no_error() {
124 // We are assured that it should parse and exist
125 let ttl = Duration::from_secs(u64::from(
126 query
127 .answer()
128 .ok()
129 .and_then(|records| {
130 records
131 .filter(|r| r.is_ok())
132 .map(|r| r.unwrap().ttl())
133 .min()
134 })
135 .unwrap_or(MAX_TTL),
136 ));
137 self.cache.lock().unwrap().put(
138 // We discard the first two bytes which are the places for ID
139 (tag, query.as_octets().slice(2..)),
140 // Clone should be cheap here
141 CacheRecord::new(msg, ttl),
142 );
143 } else {
144 info!("response errored, not caching erroneous upstream response.");
145 };
146 }
147
148 pub fn get(&self, tag: &Label, msg: &Message<Bytes>) -> Option<RecordStatus<Message<Bytes>>> {
149 let question = msg.first_question().unwrap();

Callers 1

resolveMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected