Skip to main content
ProductsDesktop toolsTASTECADDrawing reviewTASTEFILESFile managementTASTEFTPFile transferTASTESSHRemote workspaceTASTEZIPCompression and extractionTASTEWINMFile managementDeveloper toolsTASTECODERust integrated development environmentTASTESTUDIOIntegrated development and test environmentTASTEETLData integration (ETL)ServersTASTEREMOTERemote desktop serverTASTEGEOGeospatial serverTASTEMAILMail workspaceInvestingTASTESTOCKStock auto-trading desktop appGet startedDownloadsDocumentationBuyAll products
Marketplace
News
TechNewsToday's dev newsDeveloper docsProgramming languagesRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp & desktop frameworksTauriFlutterReact NativeElectronAlgorithmsAlgorithm basicsCore algorithmsAdvanced algorithmsPractical algorithms
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcaseCommunity guide
Work with usTech transferWebsite buildDesktop app buildRelease and payment pipelineSales partnerContact
ServicesRemote desktopCustom installer packages
TASTEDEV
Products

Desktop tools

TASTECADComplex drawings, opened with easeTASTEFILESJust the files you need, as fast as possibleTASTEFTPThe tidiest path for your filesTASTESSHA stronger link between you and your serversTASTEZIPPack faster, unpack saferTASTEWINMA keyboard-first file manager with two panes

Developer tools

TASTECODEEdit, build, debug and test Rust apps in one windowTASTESTUDIOFrom editing to remote tests and approved AI fixesTASTEETLMove data while you watch the values

Servers

TASTEREMOTEA remote desktop you run on your own serverTASTEGEORebuilding a GeoServer-compatible geospatial server in RustTASTEMAILTake back control of your email

Investing

TASTESTOCKStock auto-trading that follows the rules you set: when, and what

Get started

DownloadsLatest builds of every productDocsHow to use each productBuySubscriptions and perpetual licencesAll productsEvery product at a glance
All products
MarketplaceNews
Tech

News

Today's dev newsOfficial announcements on languages, frameworks, GitHub and AIDeveloper docsGuides to languages, frameworks and algorithms

Programming languages

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App & desktop frameworksTauriFlutterReact NativeElectron

Algorithms

Algorithm basicsComplexity analysis · Sorting · Searching · Basic data structures · Trees and heapsCore algorithmsGraph traversal · Shortest paths & minimum spanning trees · Dynamic programming · Greedy algorithms · Divide and conquer · BacktrackingAdvanced algorithmsString algorithms · Math and number theory · Bit manipulation · Segment trees · Union-findPractical algorithmsCoding interview strategy · LRU cache · Rate limiting · Consistent hashing
All development docs
Community
ProjectsDiscover builders and their workDevelopment logsDecisions and lessons learnedPromptsReusable instructionsAI tool issuesProblems and workarounds for Claude, Codex, GeminiShowcaseFinished resultsCommunity guideHow we build in the open
Work with us
Tech transferNative apps in Rust and eguiWebsite build10 languages, accounts, docs and downloadsDesktop app buildRust and egui, no WebViewRelease and payment pipelineSigning, MSI, deb, rpm, AppImage, hashesSales partnerRecommend us and earn 30%ContactBuilds, partnerships and investment
Services
Remote desktopReach your computer from a browserCustom installer packagesOnly the features you need, settings preloaded
Buy
EN
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Log in
Log in
TASTEDEV

From small tools to better development.

support@tastedev.netSupport TASTEDEV
ProductsProduct lineupBuyDocsDownloadsMarketplaceSupport
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcase
PoliciesAbout usPrivacy policyTerms of serviceSubscription termsRefund policyCommunity guidelines
AccountLog inSign up
Visitors
Today
Yesterday
Total views
Company
GXSOFT
Representative
CHOI YOUNG GU
Business registration number
853-44-00368
Address
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Phone
+82-10-4404-1523
Email
whitecalvin@tastedev.net
Privacy officer
CHOI YOUNG GU

© 2026 TASTEDEVProduct information is based on verified development sources.Released · improving

Developer docs
LRU cache
LRU cacheReference implementationStep-by-step guideOfficial docs and resourcesDiscussionsComments

Other algorithms

Algorithm basics5
Complexity analysisSortingSearchingBasic data structuresTrees and heaps
Core algorithms6
Graph traversalShortest paths & minimum spanning treesDynamic programmingGreedy algorithmsDivide and conquerBacktracking
Advanced algorithms5
String algorithmsMath and number theoryBit manipulationSegment treesUnion-find
Practical algorithms3
Coding interview strategyRate limitingConsistent hashing

Algorithm

LRU cache

An LRU cache evicts the least recently used entry when full, using a hash map and a doubly linked list to make get and put O(1).

Start the guideDiscussions

An LRU (least recently used) cache is a fixed-capacity cache that, when it is full, evicts the entry that has gone unused for the longest time. It relies on temporal locality, the observation that recently used data tends to be used again soon, and unlike FIFO it refreshes an entry's position on every read. The standard implementation pairs a hash map, which finds a key's node, with a doubly linked list, which keeps entries in recency order, so both get and put run in O(1) average time.

LRU, exactly or in approximate form, appears at almost every layer of a system: CPU caches, the operating system page cache, database buffer pools, Redis eviction policies, CDNs and browser caches. Standard libraries ship it too, as Python's functools.lru_cache and OrderedDict or Java's LinkedHashMap. Because it combines a hash map and a linked list in one design, it is also a classic coding interview question.

Start with the differences between eviction policies such as FIFO, LRU, LFU and TTL and with the idea of hit ratio, then trace a short request sequence by hand. Next, implement the cache yourself with a dictionary and a doubly linked list with sentinel nodes, and compare it with library versions such as OrderedDict and LinkedHashMap. Finally, work through practical problems: thread safety, cache invalidation and combining LRU with expiry.

On this page

  1. Highlights
  2. Where it is used
  3. Reference implementation
  4. Step-by-step guide
  5. Official docs and resources
  6. Discussions
  7. Comments

Highlights

Recency order

Every successful get or put moves the entry to the most recent end; when space runs out, the entry at the other end is evicted.

Hash map plus doubly linked list

The map finds a key's node directly, and the list unlinks and re-inserts nodes in O(1) to keep the order.

O(1) operations

get and put change only a constant number of pointers, so both take constant average time; space grows with capacity.

Practical variants

Real systems often use CLOCK, pseudo-LRU, sampled LRU, 2Q or W-TinyLFU to cut overhead or resist large scans.

Where it is used

  • Memoizing function results
  • Memory eviction in in-memory stores such as Redis
  • OS page caches and database buffer pools
  • CDN and browser HTTP caches

Reference implementation

A dict maps keys to nodes, and a doubly linked list between the sentinels head and tail keeps the recency order. get moves the node to the front; put evicts the node just before tail when the cache is full. Running python lru_cache.py evicts "b" and prints None 1 3.

lru_cache.py

class Node:
    __slots__ = ("key", "value", "prev", "next")

    def __init__(self, key=None, value=None):
        self.key, self.value = key, value
        self.prev = self.next = None


class LRUCache:
    def __init__(self, capacity):
        self.capacity = capacity
        self.map = {}                           # key -> Node
        self.head, self.tail = Node(), Node()   # sentinels
        self.head.next, self.tail.prev = self.tail, self.head

    def _unlink(self, node):
        node.prev.next, node.next.prev = node.next, node.prev

    def _push_front(self, node):
        node.prev, node.next = self.head, self.head.next
        self.head.next.prev = node
        self.head.next = node

    def get(self, key, default=None):
        node = self.map.get(key)
        if node is None:
            return default
        self._unlink(node)                      # touch: move to the front
        self._push_front(node)
        return node.value

    def put(self, key, value):
        if self.capacity <= 0:
            return
        node = self.map.get(key)
        if node is not None:
            node.value = value
            self._unlink(node)
            self._push_front(node)
            return
        if len(self.map) >= self.capacity:      # evict the least recently used
            lru = self.tail.prev
            self._unlink(lru)
            del self.map[lru.key]
        node = Node(key, value)
        self.map[key] = node
        self._push_front(node)


cache = LRUCache(2)
cache.put("a", 1)
cache.put("b", 2)
cache.get("a")                                  # "a" is now the most recent
cache.put("c", 3)                               # full: evicts "b"
print(cache.get("b"), cache.get("a"), cache.get("c"))  # None 1 3
python lru_cache.py

Step-by-step guide

Six chapters that take you from installation to the core ideas of LRU cache.

  1. LRU Cache Concepts
  2. How an LRU Cache Works
  3. Implementing an LRU Cache
  4. Complexity of an LRU Cache
  5. LRU Practice Problems
  6. LRU in the Real World

Official docs and resources

  • Officialfunctools.lru_cache
  • Officialcollections.OrderedDict
  • OfficialLinkedHashMap (Java SE 21)
  • OfficialKey eviction (Redis)
  • ReferenceCache replacement policies
  • ReferenceCache (computing)
  • ReferenceMap (MDN Web Docs)
  • CommunityLRU Cache (LeetCode 146)

Discussions

Start a discussion

Ask questions, share experience and trade opinions about LRU cache.

No discussions yet. Start the first one.

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.