Skip to content

Commit

Permalink
feature: the get() method now also returns the stale value as the sec…
Browse files Browse the repository at this point in the history
…ond returned value if available.
  • Loading branch information
agentzh committed Oct 29, 2014
1 parent 6196c2d commit e1abde2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ When the cache is full, the cache will automatically evict the least recently us

get
---
`syntax: data = cache:get(key)`
`syntax: data, stale_data = cache:get(key)`

Fetches a value with the key. If the key does not exist in the cache or has already expired, a `nil` value will be returned.

Starting from `v0.03`, the stale data is also returned as the second return value if available.

[Back to TOC](#table-of-contents)

delete
Expand Down
2 changes: 1 addition & 1 deletion lib/resty/lrucache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function _M.get(self, key)

if node.expire >= 0 and node.expire < ngx_now() then
-- print("expired: ", node.expire, " > ", ngx_now())
return nil
return nil, val
end
return val
end
Expand Down
2 changes: 1 addition & 1 deletion lib/resty/lrucache/pureffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function _M.get(self, key)
local expire = node.expire
if expire >= 0 and expire < ngx_now() then
-- print("expired: ", node.expire, " > ", ngx_now())
return nil
return nil, self.val_v[node_id]
end

return self.val_v[node_id]
Expand Down
2 changes: 1 addition & 1 deletion t/pureffi/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bird: 76
--- response_body
dog: 32
dog: 32
dog: nil
dog: nil32
--- no_error_log
[error]
Expand Down
2 changes: 1 addition & 1 deletion t/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bird: 76
--- response_body
dog: 32
dog: 32
dog: nil
dog: nil32
--- no_error_log
[error]
Expand Down

0 comments on commit e1abde2

Please sign in to comment.