Skip to content

Commit

Permalink
lfucache: improve LFU algorithm and structure
Browse files Browse the repository at this point in the history
Do it "more properly": use intrusive list linkage to manage three
indices:

* hash lookup
* recency
* frequency

eviction is frequency based, but in order to avoid things that were
super hot in the past and that are no longer hot clogging up the cache,
eviction will incrementally age out least recently used entries that
haven't been active in the span of some number of get/put operations.

Aging scales down the frequency value to reduce its strength, so an aged
item isn't necessarily immediately a candidate for removal, it just
makes it more likely to be picked up by the frequency based removal as
it goes unused for an extended period.
  • Loading branch information
wez committed Nov 14, 2022
1 parent 72757b8 commit 0516b61
Show file tree
Hide file tree
Showing 8 changed files with 821 additions and 185 deletions.
52 changes: 43 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lfucache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ahash = "0.8"
config = { path = "../config" }
fnv = "1.0"
intrusive-collections = "0.9"
metrics = { version="0.17", features=["std"]}

[dev-dependencies]
k9 = "0.11"
Loading

0 comments on commit 0516b61

Please sign in to comment.