openresty / openresty/lua-resty-lrucache

BUG: The expiration time may not take effect

Open
#48 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
461
Forks
114
PR merge metrics
No merged PRs in 30d

Description

lrucache:set(key, value, ttl, flags)
os.execute("sleep " .. tonumber(ttl+2))
local data, stale_data, flags = lrucache:get(key)
data is not nil

lruchache' get method
if node.expire >= 0 and node.expire < ngx_now() then
return nil, val, node.user_flags
end

ngx_now() Returns a floating-point number for the elapsed time in seconds (including milliseconds as the decimal part) from the epoch for the current time stamp from the Nginx cached time (no syscall involved unlike Lua's date library). https://github.com/openresty/lua-nginx-module#ngxnow

Is it better to add an ngx.update_time()?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lrucache's get method and the reported expiration check using ngx_now(). Reproduce the set/get sequence with os.execute("sleep " .. tonumber(ttl+2)), then verify whether the cached time is refreshed before expiration is evaluated; done means the entry is stale and data is nil after the TTL has elapsed.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.