A C++ implementation of an LRU (Least Recently Used) cache that supports constant-time get and put operations.
The project includes an interactive command-line demo and basic tests to verify correctness.
- Fixed-capacity cache with automatic eviction
- O(1) average-time
getandputoperations - Least recently used item is evicted when capacity is exceeded
- Interactive CLI to experiment with cache behavior
- Simple assertion-based tests
- C++
- STL (
std::unordered_map,std::list) - CMake
- A hash map provides fast lookup from key to cache entry
- A doubly linked list tracks usage order
- Most recently used items are kept at the front
- Least recently used items are removed when the cache is full
- C++ compiler that supports C++17
- CMake
- An IDE such as CLion, or a terminal environment
- Clone the repository to your local machine.
- Open the project folder in your IDE (for example, CLion).
- Build the project using CMake.
- Run the
lru_cachetarget to start the interactive demo. - Follow the on-screen instructions to interact with the cache.
- Build and run the
lru_cachetarget. - Enter a cache capacity when prompted.
- Use the following commands:
put <key> <value>— insert or update an entryget <key>— retrieve a valueprint— display cache contents (MRU → LRU)quit— exit the program