@@ -87,6 +87,7 @@ fn keyed(a: &str, b: &str) -> usize {
8787
8888```rust,no_run
8989use cached::proc_macro::once;
90+ use std::time::Duration;
9091
9192/// Only cache the initial function call.
9293/// Function will be re-executed after the cache
@@ -126,6 +127,7 @@ fn doesnt_compile() -> Result<String, ()> {
126127```rust,no_run,ignore
127128use cached::proc_macro::io_cached;
128129use cached::AsyncRedisCache;
130+ use std::time::Duration;
129131use thiserror::Error;
130132
131133#[derive(Error, Debug, PartialEq, Clone)]
@@ -143,7 +145,7 @@ enum ExampleError {
143145 map_error = r##"|e| ExampleError::RedisError(format!("{:?}", e))"##,
144146 ty = "AsyncRedisCache<u64, String>",
145147 create = r##" {
146- AsyncRedisCache::new("cached_redis_prefix", 1 )
148+ AsyncRedisCache::new("cached_redis_prefix", Duration::from_secs(1) )
147149 .set_refresh(true)
148150 .build()
149151 .await
@@ -220,6 +222,8 @@ Due to the requirements of storing arguments and return values in a global cache
220222#[ doc( hidden) ]
221223pub extern crate once_cell;
222224
225+ use std:: time:: Duration ;
226+
223227#[ cfg( feature = "proc_macro" ) ]
224228#[ cfg_attr( docsrs, doc( cfg( feature = "proc_macro" ) ) ) ]
225229pub use proc_macro:: Return ;
@@ -372,20 +376,20 @@ pub trait Cached<K, V> {
372376 }
373377
374378 /// Return the lifespan of cached values (time to eviction)
375- fn cache_lifespan ( & self ) -> Option < u64 > {
379+ fn cache_lifespan ( & self ) -> Option < Duration > {
376380 None
377381 }
378382
379383 /// 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 > {
381385 None
382386 }
383387
384388 /// Remove the lifespan for cached values, returns the old value.
385389 ///
386390 /// For cache implementations that don't support retaining values indefinitely, this method is
387391 /// a no-op.
388- fn cache_unset_lifespan ( & mut self ) -> Option < u64 > {
392+ fn cache_unset_lifespan ( & mut self ) -> Option < Duration > {
389393 None
390394 }
391395}
@@ -445,20 +449,20 @@ pub trait IOCached<K, V> {
445449 fn cache_set_refresh ( & mut self , refresh : bool ) -> bool ;
446450
447451 /// Return the lifespan of cached values (time to eviction)
448- fn cache_lifespan ( & self ) -> Option < u64 > {
452+ fn cache_lifespan ( & self ) -> Option < Duration > {
449453 None
450454 }
451455
452456 /// 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 > {
454458 None
455459 }
456460
457461 /// Remove the lifespan for cached values, returns the old value.
458462 ///
459463 /// For cache implementations that don't support retaining values indefinitely, this method is
460464 /// a no-op.
461- fn cache_unset_lifespan ( & mut self ) -> Option < u64 > {
465+ fn cache_unset_lifespan ( & mut self ) -> Option < Duration > {
462466 None
463467 }
464468}
@@ -479,20 +483,20 @@ pub trait IOCachedAsync<K, V> {
479483 fn cache_set_refresh ( & mut self , refresh : bool ) -> bool ;
480484
481485 /// Return the lifespan of cached values (time to eviction)
482- fn cache_lifespan ( & self ) -> Option < u64 > {
486+ fn cache_lifespan ( & self ) -> Option < Duration > {
483487 None
484488 }
485489
486490 /// 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 > {
488492 None
489493 }
490494
491495 /// Remove the lifespan for cached values, returns the old value.
492496 ///
493497 /// For cache implementations that don't support retaining values indefinitely, this method is
494498 /// a no-op.
495- fn cache_unset_lifespan ( & mut self ) -> Option < u64 > {
499+ fn cache_unset_lifespan ( & mut self ) -> Option < Duration > {
496500 None
497501 }
498502}
0 commit comments