Skip to content

forging-moon/lfu-cache

Repository files navigation

LFU Cache Visualizer

An interactive web application for visualizing and understanding LFU (Least Frequently Used) cache eviction policies. Compare LFU vs LRU behavior side-by-side and build intuition for caching strategies through hands-on experimentation.

Live Demo

https://forging-moon.github.io/lfu-cache/

Features

  • Interactive LFU Cache: Adjust capacity (2-20 items) and perform get/put operations with real-time visual feedback
  • Side-by-side Comparison: Toggle "Compare Mode" to see how LRU makes different eviction decisions on the same access pattern
  • Pattern Playback: Auto-play preset patterns (sequential, hot keys, alternating, random) or input custom sequences
  • Visual Feedback: Color-coded indicators for hits (green), misses (amber), and evictions (red)
  • Frequency Visualization: Each cache entry displays its access frequency with gradient-colored badges
  • Operation History: Complete log of all operations with timestamps and outcomes
  • Hit/Miss Statistics: Real-time tracking of cache performance metrics
  • Mobile Responsive: Works on 375px+ viewports with touch-friendly controls

How to Use

  1. Adjust Capacity: Use the slider to set cache size (2-20 items)
  2. Manual Operations:
    • Enter a key/value and click Put to add items
    • Enter a key and click Get to retrieve items
  3. Pattern Playback: Select a preset pattern and click Play to watch cache behavior automatically
  4. Compare Mode: Toggle the switch to see LRU eviction decisions side-by-side
  5. Step Through: Use Step button to advance patterns one operation at a time
  6. Clear: Reset the cache to start fresh experiments

Technical Details

  • Implementation: O(1) LFU using frequency buckets and hash maps
  • Tie-breaking: When frequencies are equal, oldest entry (by insertion time) is evicted
  • Stack: Vanilla HTML/CSS/JavaScript — no build step, no dependencies
  • Deployment: GitHub Pages

Local Development

git clone https://github.com/forging-moon/lfu-cache.git
cd lfu-cache
# Open index.html in your browser, or:
python3 -m http.server 8000

License

MIT — Part of the Forging Moon collection of interactive computer science visualizations.

About

Interactive LFU cache visualizer - learn caching strategies hands-on

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages