<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>lru on 空树之空</title><link>https://yezihack.github.io/tags/lru/</link><description>Recent content in lru on 空树之空</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Tue, 13 Oct 2026 17:28:39 +0800</lastBuildDate><atom:link href="https://yezihack.github.io/tags/lru/index.xml" rel="self" type="application/rss+xml"/><item><title>深入剖析 hashicorp/golang-lru：Go 生态最流行的 LRU 缓存库</title><link>https://yezihack.github.io/golang-lru/</link><pubDate>Tue, 13 Oct 2026 17:28:39 +0800</pubDate><guid>https://yezihack.github.io/golang-lru/</guid><description>基于仓库 hashicorp/golang-lru（v2 主分支，commit 235099c）源码分析。 数据截至 2026-10：5.1k+ Stars / 540+ Forks / 被 93,000+ 仓库依赖，MPL-2.0 许可证。
一、它是什么 golang-lru 是 HashiCorp 开源的 Go 语言 LRU 缓存库，源自 Brad Fitzpatrick 的 groupcache 中的 LRU 实现。它表面上看只是&amp;quot;一个哈希表加一个双向链表&amp;quot;，但被 Consul、Nomad、Vault 以及 GitHub 上九万多个仓库依赖，成为 Go 生态事实意义上的标准 LRU 实现。
它提供了四种缓存：
缓存 包 算法 特点 lru.Cache 主模块 标准 LRU 简单、够用、开销最低 lru.TwoQueueCache 主模块 2Q 抗突发扫描，约 2x 开销 arc.ARCCache 独立模块 arc/v2 ARC 自适应免调参，IBM 专利 expirable.LRU 主模块 LRU + TTL 支持过期时间 一个看似简单的库，把这四种变体都实现了，而且代码总量不过三千行——这本身就值得拆开看看。
二、仓库结构：三层加一个例外 golang-lru/ ├── lru.</description></item></channel></rss>