A clean and efficient fixed-capacity Least Recently Used (LRU) cache implemented in pure C.
The project focuses on data-structure design, predictable performance, memory management, and a small reusable API.
An LRU cache keeps recently accessed items available while automatically evicting the least recently used item when its capacity is reached.
LRUCacheExpress provides average O(1) get and put operations.
- Fixed-capacity LRU cache
- O(1) average-time
get - O(1) average-time
put - Modular C implementation
- Reusable public API
- Dedicated tests
- Explicit memory management
| Operation | Average |
|---|---|
| Get | O(1) |
| Put | O(1) |
| Eviction | O(1) |
The constant-time design is achieved by combining fast lookup with an ordering structure that tracks recent usage.
LRUCacheExpress/
├── includes/
├── sources/
├── tests/
├── LICENSE
└── README.md
The project is written in C. A typical build can be performed with:
cc -Iincludes sources/*.c -o lru_cacheAdapt the command to the compiler and source files required by your environment.
The repository contains a dedicated tests/ directory for validating cache behavior.
Typical cases to test include:
- Inserting new entries
- Updating existing entries
- Reading an existing key
- Reading a missing key
- Capacity overflow
- Least-recently-used eviction
- Repeated access and recency updates
The goal is to demonstrate how a commonly used systems/data-structure concept can be implemented from scratch in C while keeping the public API small and the runtime characteristics predictable.
MIT License.