Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 2.6.1 #123

Merged
merged 9 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
matrix:
os: [ubuntu-latest]
openresty:
- 1.21.4.1
- 1.25.3.1
- 1.21.4.3
- 1.19.9.1
- 1.19.3.2
- 1.17.8.2
Expand Down
40 changes: 27 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
# Table of Contents

- [2.6.0](#2.6.0)
- [2.5.0](#2.5.0)
- [2.4.1](#2.4.1)
- [2.4.0](#2.4.0)
- [2.3.0](#2.3.0)
- [2.2.1](#2.2.1)
- [2.2.0](#2.2.0)
- [2.1.0](#2.1.0)
- [2.0.2](#2.0.2)
- [2.0.1](#2.0.1)
- [2.0.0](#2.0.0)
- [1.0.1](#1.0.1)
- [1.0.0](#1.0.0)
- [2.6.1](#261)
- [2.6.0](#260)
- [2.5.0](#250)
- [2.4.1](#241)
- [2.4.0](#240)
- [2.3.0](#230)
- [2.2.1](#221)
- [2.2.0](#220)
- [2.1.0](#210)
- [2.0.2](#202)
- [2.0.1](#201)
- [2.0.0](#200)
- [1.0.1](#101)
- [1.0.0](#100)

## [2.6.1]

> Released on: 2024/01/30

#### Fixed

- Ensure the `l1_serializer` callback option is properly invoked in a couple of
`get()` edge-cases.
[#123](https://github.com/thibaultcha/lua-resty-mlcache/pull/123)

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

## [2.6.0]

Expand Down Expand Up @@ -255,6 +268,7 @@ Initial release.

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

[2.6.1]: https://github.com/thibaultcha/lua-resty-mlcache/compare/2.6.0...2.6.1
[2.6.0]: https://github.com/thibaultcha/lua-resty-mlcache/compare/2.5.0...2.6.0
[2.5.0]: https://github.com/thibaultcha/lua-resty-mlcache/compare/2.4.1...2.5.0
[2.4.1]: https://github.com/thibaultcha/lua-resty-mlcache/compare/2.4.0...2.4.1
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017-2023 Thibault Charbonnier
Copyright (c) 2017-2024 Thibault Charbonnier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Tests matrix results:
| `1.19.3.x` | :heavy_check_mark:
| `1.19.9.x` | :heavy_check_mark:
| `1.21.4.x` | :heavy_check_mark:
| `1.25.3.x` | :heavy_check_mark:
| > | not tested

[Back to TOC](#table-of-contents)
Expand Down Expand Up @@ -444,6 +445,10 @@ in the cache **and** no callback is provided, `get()` will return `nil, nil,
with return values such as `nil, nil, 1`, where 1 signifies a **negative cached
item** found in L1 (cached `nil`).

Not providing a `callback` function allows implementing cache lookup patterns
that are guaranteed to be on-cpu for a more constant, smoother latency tail end
(e.g. with values refreshed in background timers via `set()`).

```lua
local value, err, hit_lvl = cache:get("key")
if value == nil then
Expand Down
36 changes: 29 additions & 7 deletions lib/resty/mlcache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ end


local _M = {
_VERSION = "2.6.0",
_VERSION = "2.6.1",
_AUTHOR = "Thibault Charbonnier",
_LICENSE = "MIT",
_URL = "https://github.com/thibaultcha/lua-resty-mlcache",
Expand Down Expand Up @@ -394,12 +394,8 @@ function _M.new(name, shm, opts)
end


local function set_lru(self, key, value, ttl, neg_ttl, l1_serializer)
if value == nil then
ttl = neg_ttl
value = CACHE_MISS_SENTINEL_LRU

elseif l1_serializer then
local function l1_serialize(value, l1_serializer)
if value ~= nil and l1_serializer then
local ok, err
ok, value, err = pcall(l1_serializer, value)
if not ok then
Expand All @@ -415,6 +411,21 @@ local function set_lru(self, key, value, ttl, neg_ttl, l1_serializer)
end
end

return value
end


local function set_lru(self, key, value, ttl, neg_ttl, l1_serializer)
local value, err = l1_serialize(value, l1_serializer)
if err then
return nil, err
end

if value == nil then
value = CACHE_MISS_SENTINEL_LRU
ttl = neg_ttl
end

if ttl == 0 then
-- indefinite ttl for lua-resty-lrucache is 'nil'
ttl = nil
Expand Down Expand Up @@ -555,6 +566,11 @@ local function get_shm_set_lru(self, key, shm_key, l1_serializer)
end

if went_stale then
value, err = l1_serialize(value, l1_serializer)
if err then
return nil, err
end

return value, nil, went_stale
end

Expand All @@ -574,6 +590,11 @@ local function get_shm_set_lru(self, key, shm_key, l1_serializer)
-- value has less than 1ms of lifetime in the shm, avoid
-- setting it in LRU which would be wasteful and could
-- indefinitely cache the value when ttl == 0
value, err = l1_serialize(value, l1_serializer)
if err then
return nil, err
end

return value, nil, nil, is_stale
end
end
Expand Down Expand Up @@ -687,6 +708,7 @@ end

local function run_callback(self, key, shm_key, data, ttl, neg_ttl,
went_stale, l1_serializer, resurrect_ttl, shm_set_tries, cb, ...)

local lock, err = resty_lock:new(self.shm_locks, self.resty_lock_opts)
if not lock then
return nil, "could not create lock: " .. err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package = "lua-resty-mlcache"
version = "2.6.0-2"
version = "2.6.1-1"
source = {
url = "git+https://github.com/thibaultcha/lua-resty-mlcache",
tag = "2.6.0"
tag = "2.6.1"
}
description = {
summary = "Layered caching library for OpenResty",
Expand Down