File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -120,9 +120,20 @@ where
120120pub struct Config {
121121 /// Time-to-live for cache entries
122122 ///
123- /// Entries older than this duration will be evicted from the cache.
123+ /// Entries not seen for at least this long will be evicted from the cache.
124124 /// Default is 1 hour.
125- pub ttl : Duration ,
125+ ttl : Duration ,
126+ }
127+
128+ impl Config {
129+ /// Set the time-to-live for cache entries
130+ ///
131+ /// Entries not seen for at least this long will be evicted from the cache.
132+ #[ must_use]
133+ pub fn ttl ( mut self , ttl : Duration ) -> Self {
134+ self . ttl = ttl;
135+ self
136+ }
126137}
127138
128139impl Default for Config {
@@ -199,7 +210,7 @@ where
199210 // Check if the predicate value changed or entry doesn't exist
200211 let changed = me. cache . get ( & key) . map ( |entry| entry. hash ) != Some ( val) ;
201212
202- // Update cache with new hash and timestamp
213+ // Upsert the cache entry with new hash and timestamp
203214 me. cache . insert ( key, CacheEntry {
204215 hash : val,
205216 last_seen : now,
@@ -402,9 +413,7 @@ pub(crate) mod tests {
402413 } ;
403414
404415 // Use a very short TTL for testing
405- let config = Config {
406- ttl : Duration :: from_millis ( 50 ) ,
407- } ;
416+ let config = Config :: default ( ) . ttl ( Duration :: from_millis ( 50 ) ) ;
408417
409418 // Use a channel so we can send items with delays
410419 let ( mut tx, rx) = mpsc:: unbounded ( ) ;
You can’t perform that action at this time.
0 commit comments