@@ -87,6 +87,7 @@ fn keyed(a: &str, b: &str) -> usize {
87
87
88
88
```rust,no_run
89
89
use cached::proc_macro::once;
90
+ use std::time::Duration;
90
91
91
92
/// Only cache the initial function call.
92
93
/// Function will be re-executed after the cache
@@ -126,6 +127,7 @@ fn doesnt_compile() -> Result<String, ()> {
126
127
```rust,no_run,ignore
127
128
use cached::proc_macro::io_cached;
128
129
use cached::AsyncRedisCache;
130
+ use std::time::Duration;
129
131
use thiserror::Error;
130
132
131
133
#[derive(Error, Debug, PartialEq, Clone)]
@@ -143,7 +145,7 @@ enum ExampleError {
143
145
map_error = r##"|e| ExampleError::RedisError(format!("{:?}", e))"##,
144
146
ty = "AsyncRedisCache<u64, String>",
145
147
create = r##" {
146
- AsyncRedisCache::new("cached_redis_prefix", 1 )
148
+ AsyncRedisCache::new("cached_redis_prefix", Duration::from_secs(1) )
147
149
.set_refresh(true)
148
150
.build()
149
151
.await
@@ -220,6 +222,8 @@ Due to the requirements of storing arguments and return values in a global cache
220
222
#[ doc( hidden) ]
221
223
pub extern crate once_cell;
222
224
225
+ use std:: time:: Duration ;
226
+
223
227
#[ cfg( feature = "proc_macro" ) ]
224
228
#[ cfg_attr( docsrs, doc( cfg( feature = "proc_macro" ) ) ) ]
225
229
pub use proc_macro:: Return ;
@@ -372,20 +376,20 @@ pub trait Cached<K, V> {
372
376
}
373
377
374
378
/// Return the lifespan of cached values (time to eviction)
375
- fn cache_lifespan ( & self ) -> Option < u64 > {
379
+ fn cache_lifespan ( & self ) -> Option < Duration > {
376
380
None
377
381
}
378
382
379
383
/// Set the lifespan of cached values, returns the old value
380
- fn cache_set_lifespan ( & mut self , _seconds : u64 ) -> Option < u64 > {
384
+ fn cache_set_lifespan ( & mut self , _ttl : Duration ) -> Option < Duration > {
381
385
None
382
386
}
383
387
384
388
/// Remove the lifespan for cached values, returns the old value.
385
389
///
386
390
/// For cache implementations that don't support retaining values indefinitely, this method is
387
391
/// a no-op.
388
- fn cache_unset_lifespan ( & mut self ) -> Option < u64 > {
392
+ fn cache_unset_lifespan ( & mut self ) -> Option < Duration > {
389
393
None
390
394
}
391
395
}
@@ -445,20 +449,20 @@ pub trait IOCached<K, V> {
445
449
fn cache_set_refresh ( & mut self , refresh : bool ) -> bool ;
446
450
447
451
/// Return the lifespan of cached values (time to eviction)
448
- fn cache_lifespan ( & self ) -> Option < u64 > {
452
+ fn cache_lifespan ( & self ) -> Option < Duration > {
449
453
None
450
454
}
451
455
452
456
/// Set the lifespan of cached values, returns the old value.
453
- fn cache_set_lifespan ( & mut self , _seconds : u64 ) -> Option < u64 > {
457
+ fn cache_set_lifespan ( & mut self , _ttl : Duration ) -> Option < Duration > {
454
458
None
455
459
}
456
460
457
461
/// Remove the lifespan for cached values, returns the old value.
458
462
///
459
463
/// For cache implementations that don't support retaining values indefinitely, this method is
460
464
/// a no-op.
461
- fn cache_unset_lifespan ( & mut self ) -> Option < u64 > {
465
+ fn cache_unset_lifespan ( & mut self ) -> Option < Duration > {
462
466
None
463
467
}
464
468
}
@@ -479,20 +483,20 @@ pub trait IOCachedAsync<K, V> {
479
483
fn cache_set_refresh ( & mut self , refresh : bool ) -> bool ;
480
484
481
485
/// Return the lifespan of cached values (time to eviction)
482
- fn cache_lifespan ( & self ) -> Option < u64 > {
486
+ fn cache_lifespan ( & self ) -> Option < Duration > {
483
487
None
484
488
}
485
489
486
490
/// Set the lifespan of cached values, returns the old value
487
- fn cache_set_lifespan ( & mut self , _seconds : u64 ) -> Option < u64 > {
491
+ fn cache_set_lifespan ( & mut self , _ttl : Duration ) -> Option < Duration > {
488
492
None
489
493
}
490
494
491
495
/// Remove the lifespan for cached values, returns the old value.
492
496
///
493
497
/// For cache implementations that don't support retaining values indefinitely, this method is
494
498
/// a no-op.
495
- fn cache_unset_lifespan ( & mut self ) -> Option < u64 > {
499
+ fn cache_unset_lifespan ( & mut self ) -> Option < Duration > {
496
500
None
497
501
}
498
502
}
0 commit comments