Skip to content

Back to Work
2024

memecache

A minimal, zero-dependency, in-memory caching library in C++ — built for understanding, not for frameworks.

Overview

A minimal, thread-safe caching library built entirely in C++ using the Standard Template Library — no external dependencies, no bloat. Supports multiple cache eviction policies and can extend custom eviction policies through a clean abstract interface.


Eviction Policies

The library implements common cache replacement strategies:

  • FIFO — First-In/First-Out
  • LIFO — Last-In/First-Out
  • LRU — Least Recently Used

An exhaustive list of cache algorithms for reference: Wikipedia — Cache Algorithms.


Thread Safety

The library is thread-safe by design — multiple threads can perform concurrent

Put
and
Get
operations on the same cache instance without external synchronization. Internally uses std::mutex to guard shared state, with std::lock_guard for RAII-style lock management.


Custom Policies

To implement a custom eviction policy, include the

cache_policy.hpp
header containing the ICachePolicy abstract interface and override four methods:

  • Insert(const Key& key)
    — handles element insertion
  • Touch(const Key& key)
    — handles cache hit / access
  • Erase(const Key& key)
    — handles deletion
  • ReplacementCandidate()
    — returns the key to evict

The design prioritized correctness and simplicity over feature count. Every line of code has a reason to exist — a deliberate exercise in systems-level thinking: understanding memory layout, cache coherence implications, and the cost of abstraction in performance-critical code.


Tech Stack

C++
STL
Design Patterns
Templates