Code Explainers

Code explainers tagged #eviction

ruby
class LRUCache
  def initialize(capacity)
    raise ArgumentError, "capacity must be positive" unless capacity.positive?
 

How an LRU cache works in Ruby

caching eviction hash-ordering
Intermediate 7 steps
python
from collections import OrderedDict
from typing import Any, Hashable, Optional
 
 

Building an LRU cache with OrderedDict

caching eviction data-structures
Intermediate 6 steps
java
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;
 

A thread-safe LRU cache in Java

lru-cache concurrency linkedhashmap
Intermediate 7 steps
typescript
class LRUCache<K, V> {
  private readonly capacity: number;
  private readonly map: Map<K, V>;
 

Building an LRU cache on a JS Map

caching data-structures generics
Intermediate 8 steps