Skip to content

v1.0.0

Latest

Choose a tag to compare

@github-actions github-actions released this 22 Jul 23:18
· 103 commits to main since this release

LRUCache v1.0.0

The first stable release of LRUCache, a high-performance LRU cache implementation for modern C++.

Highlights

  • O(1) average-case lookup, insertion, and removal.
  • Custom memory pool for efficient node allocation and reuse.
  • Open-addressing hash table with linear probing.
  • Intrusive doubly linked list for efficient LRU ordering.
  • Automatic eviction of the least recently used entries.
  • Support for put() and emplace() operations.
  • Support for get(), peek(), and contains() lookups.
  • Support for erase() and clear() operations.
  • Dynamic cache resizing and capacity management.
  • Move construction and move assignment support, including safe
    self-move-assignment; a moved-from cache is left empty and safe to
    destroy or move-assign into again.
  • Cache hit and miss statistics.
  • Exception-safety and allocation-failure handling.

Performance

The implementation is designed with performance and memory efficiency in mind.

  • Custom node pool reduces dynamic allocation overhead.
  • Intrusive LRU list provides constant-time recency updates.
  • Hash-table slots directly track nodes for efficient deletion.
  • Open addressing provides cache-friendly hash-table access.
  • Hash-table load factor is bounded to maintain efficient probing.
  • Reusable node storage minimizes allocation overhead during eviction and insertion.

Benchmarks

Measured against stdLRU (std::list + std::unordered_map) at 10K / 100K / 1M
iterations. Full results: benchmarks/results/v1_0_0.md.

Operation CachePro (1M) stdLRU (1M) Δ
Reserve() 617.40 us 12.83 ms +1978.5%
Clear() + Refill 863.73 ms 4.27 s +394.3%
Move-construct 1.00 s 4.69 s +367.9%
Contains() Miss 1.24 ms 4.98 ms +300.6%
Get() Miss 2.50 ms 4.97 ms +99.3%
Emplace() Insert 44.67 ms 76.21 ms +70.6%
Put() Insert 46.34 ms 45.82 ms -1.1%
Get() Hit 2.18 ms 1.87 ms -14.2%
Erase() Existing 33.26 ms 27.36 ms -17.7%
Resize() Grow 25.21 ms 17.53 ms -30.5%
Shrink To Fit() 1.11 s 518.93 ms -53.4%
Construct Empty 3.29 s 5.30 ms -99.8%

CachePro's pool-based, open-addressing design pays off most on miss-heavy
workloads (Contains()/Get() misses), bulk churn (Clear() + refill), and
Reserve() — a genuine no-op here versus a real rehash in stdLRU.

The trade-off: the pool and table are allocated once, eagerly, at
construction — so Construct Empty is consistently slower than stdLRU's
lazy allocation, and calls that trigger a reallocation (Resize() Grow,
Shrink To Fit()) pay that cost directly rather than amortizing it.

Testing

The project includes a comprehensive test suite covering:

  • Unit tests
  • Integration tests
  • Lifecycle tests
  • Move semantics
  • Regression tests
  • Exception safety
  • Allocation failure handling
  • Resize behavior
  • Hash-table edge cases
  • Cache eviction order
  • Pool reuse
  • Statistics tracking
  • External synchronization contracts

Code Coverage

The current test suite achieves:

  • 99.0% line coverage
  • 96.2% function coverage

Coverage reports exclude test infrastructure and third-party dependencies, focusing on the CachePro library implementation.

Continuous Integration

Automated builds and tests are configured for:

  • GCC — Debug
  • GCC — Release
  • Clang — Debug
  • Clang — Release
  • MSVC — Debug
  • MSVC — Release
  • AppleClang — Debug
  • AppleClang — Release

Release

This release represents the first stable version of LRUCache and establishes the initial API, memory-management design, testing infrastructure, and cross-platform CI pipeline.

Installation

Clone the repository and integrate LRUCache into your C++ project using the provided CMake configuration.

See the project documentation for build instructions, API usage, and integration details.