-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
23 lines (18 loc) · 880 Bytes
/
Copy pathMain.java
File metadata and controls
23 lines (18 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.sayandip.kvstore;
public class Main {
public static void main(String[] args) throws InterruptedException {
KVStore<String, String> store = new KVStore<>(3);
store.put("a", "apple");
store.put("b", "banana");
store.put("c", "cherry");
System.out.println("get a: " + store.get("a")); // touching a makes it MRU
store.put("d", "date"); // capacity=3 exceeded -> evicts LRU, which is now "b"
System.out.println("get b (expect evicted -> null): " + store.get("b"));
System.out.println("get d: " + store.get("d"));
store.put("temp", "will expire", 2); // 2 second TTL
System.out.println("get temp (immediate): " + store.get("temp"));
Thread.sleep(2500);
System.out.println("get temp (after ttl -> expect null): " + store.get("temp"));
store.shutdown();
}
}