Skip to content

Commit

Permalink
docs: fix per-entry expiration policy documentation
Browse files Browse the repository at this point in the history
* remove unused imports
* add feature time to tokio, since the example uses tokio::time
* do cache.run_pending_tasks() before emitting the entry count so that it's accurate
  • Loading branch information
arcstur authored May 3, 2024
1 parent 26bbb2a commit a2d09e5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/future/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ use std::sync::atomic::{AtomicBool, Ordering};
/// //
/// // [dependencies]
/// // moka = { version = "0.12", features = ["future"] }
/// // tokio = { version = "1", features = ["rt-multi-thread", "macros" ] }
/// // tokio = { version = "1", features = ["rt-multi-thread", "macros", "time" ] }
///
/// use moka::{future::{Cache, FutureExt}, Expiry, notification::ListenerFuture};
/// use moka::{future::Cache, Expiry};
/// use std::time::{Duration, Instant};
///
/// // In this example, we will create a `future::Cache` with `u32` as the key, and
Expand Down Expand Up @@ -403,6 +403,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
/// // Sleep for 6 seconds. Key 0 should expire.
/// println!("\nSleeping for 6 seconds...\n");
/// tokio::time::sleep(Duration::from_secs(6)).await;
/// cache.run_pending_tasks().await;
/// println!("Entry count: {}", cache.entry_count());
///
/// // Verify that key 0 has been evicted.
Expand All @@ -413,6 +414,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
/// // Sleep for 10 more seconds. Key 1 should expire.
/// println!("\nSleeping for 10 seconds...\n");
/// tokio::time::sleep(Duration::from_secs(10)).await;
/// cache.run_pending_tasks().await;
/// println!("Entry count: {}", cache.entry_count());
///
/// // Verify that key 1 has been evicted.
Expand All @@ -425,6 +427,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
///
/// println!("\nSleeping for a second...\n");
/// tokio::time::sleep(Duration::from_secs(1)).await;
/// cache.run_pending_tasks().await;
/// println!("Entry count: {}", cache.entry_count());
///
/// println!("\nDone!");
Expand Down

0 comments on commit a2d09e5

Please sign in to comment.