Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 908 Bytes

README.md

File metadata and controls

52 lines (37 loc) · 908 Bytes

cache.nvim

lru and lfu cache for neovim lua

Example

local lru = require("cache.lru")
local lfu = require("cache.lfu")
local function dump(v)
    print(vim.inspect(v))
end

lru

local rc = lru.init(3) -- capacity 3

rc:set("hello", { "hello", "world", "uga" })
rc:set(12, 3456789)
rc:set(true, "false")

dump(rc:get(true))
dump(rc:get("hello"))
dump(rc:get(12))

rc:set(false, "true") -- over capacity
dump(rc:get(true)) -- Removeda the least recently used cache.

lfu

local fc = lru.init(3) -- capacity 3

fc:set("hello", { "hello", "world", "uga" })
fc:set(12, 3456789)
fc:set(true, "false")

dump(fc:get(true)) -- freq = 2
dump(fc:get(true)) -- freq = 3
dump(fc:get("hello")) -- freq = 2
dump(fc:get(12)) -- freq = 2

fc:set(false, "true") -- over capacity
dump(rc:get("hello")) -- Removed the least frequent cache with the oldest accesses.

License

CC0