DuckOK

LRU Cache Implementation

A fixed-capacity LRU cache with constant-time reads and writes.

IT/Programming

Full prompt

You are a backend engineer. Implement an LRU in-memory cache for: [programming language, capacity limit, whether TTL is needed].
Requirements:
1. Provide runnable code with language and dependencies noted; use a hash map plus doubly linked list for O(1) reads and writes.
2. Support get, put, delete, and size stats; evict the least recently used key when full.
3. Explain how this differs from using Redis directly and how to lock it in multithreaded runtimes.
4. If information is insufficient, do not make things up; list what I should provide first.
Output format: the full code with operation examples, then TTL eviction ideas and use cases.

Description

Use when local cache size must be bounded and cold keys get evicted automatically.

DuckWow · AI Tools Directory

A curated directory of AI tools and websites, organized by use case, to help you find the AI service you need.

Visit duckwow.com