https://github.com/eshan-sud/cache-simulator
A simple LRU-based Cache Simulator
https://github.com/eshan-sud/cache-simulator
cache-simulator cpp lru-cache
Last synced: about 1 year ago
JSON representation
A simple LRU-based Cache Simulator
- Host: GitHub
- URL: https://github.com/eshan-sud/cache-simulator
- Owner: eshan-sud
- License: mit
- Created: 2025-02-11T10:45:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-11T11:14:57.000Z (over 1 year ago)
- Last Synced: 2025-02-11T12:26:08.752Z (over 1 year ago)
- Topics: cache-simulator, cpp, lru-cache
- Language: C++
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cache Simulator
Implemented in C++, an LRU (Least Recently Used) cache simulator
Tools : C++, Operating Systems concepts
Compilation:
g++ src/lru_cache.cpp -o src/lru_cache
./src/lru_cache
Explanation of Output:
| Step | Operation | Expected Output | Explanation |
|------|---------------------------------------|-----------------|------------------------------------------------------------------------------|
| 1 | put(1,100), put(2,200), put(3,300) | N/A | Cache is now {1:100, 2:200, 3:300} |
| 2 | get(1) | 100 | Accessing key 1 makes it Most Recently Used (MRU) |
| 3 | put(4,400) | N/A | Evicts key 2 (Least Recently Used - LRU). Cache is now {1:100, 3:300, 4:400} |
| 4 | get(2) | -1 | Key 2 was evicted, so it’s not in the cache |
| 5 | get(3) | 300 | Key 3 is present in the cache |
| 6 | get(4) | 400 | Key 4 is present in the cache |
| 7 | put(5,500) | N/A | Evicts key 1 (Least Recently Used - LRU). Cache is now {3:300, 4:400, 5:500} |
| 8 | get(1) | -1 | Key 1 was evicted |
| 9 | get(5) | 500 | Key 5 is present in the cache |