Skip to content

Commit

Permalink
设置带有ttl的Lru
Browse files Browse the repository at this point in the history
  • Loading branch information
w273732573 committed Jun 23, 2024
1 parent 948d805 commit fa67f52
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 34 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"cmake.configureOnOpen": true
"cmake.configureOnOpen": true,
"rust-analyzer.cargo.features": [
"ttl"
],
}
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ opt-level = 3
debug = true

[features]
hashbrown=[]
hashbrown=[]
ttl=[]
11 changes: 11 additions & 0 deletions examples/lru.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@

use algorithm::LruCache;

fn run_ttl() {
let mut lru = LruCache::new(3);
lru.insert_with_ttl("help", "ok", 1);
assert_eq!(lru.len(), 1);
std::thread::sleep(std::time::Duration::from_secs(1));
assert_eq!(lru.get("help"), None);
assert_eq!(lru.len(), 0);
}
fn main() {
let mut lru = LruCache::new(3);
lru.insert("now", "ok");
Expand All @@ -10,4 +19,6 @@ fn main() {
assert_eq!(lru.get("hello"), Some(&"algorithm"));
assert_eq!(lru.get("this"), Some(&"lru"));
assert_eq!(lru.get("now"), None);

run_ttl();
}
Loading

0 comments on commit fa67f52

Please sign in to comment.