aboutsummaryrefslogtreecommitdiffstats
path: root/server/resty/session/strategies/regenerate.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server/resty/session/strategies/regenerate.lua')
-rw-r--r--server/resty/session/strategies/regenerate.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/server/resty/session/strategies/regenerate.lua b/server/resty/session/strategies/regenerate.lua
new file mode 100644
index 0000000..f2a97dd
--- /dev/null
+++ b/server/resty/session/strategies/regenerate.lua
@@ -0,0 +1,43 @@
+local default = require "resty.session.strategies.default"
+
+local concat = table.concat
+
+local strategy = {
+ regenerate = true,
+ start = default.start,
+ destroy = default.destroy,
+ close = default.close,
+}
+
+local function key(source)
+ if source.usebefore then
+ return concat{ source.id, source.usebefore }
+ end
+
+ return source.id
+end
+
+function strategy.open(session, cookie, keep_lock)
+ return default.load(session, cookie, key(cookie), keep_lock)
+end
+
+function strategy.touch(session, close)
+ return default.modify(session, "touch", close, key(session))
+end
+
+function strategy.save(session, close)
+ if session.present then
+ local storage = session.storage
+ if storage.ttl then
+ storage:ttl(session.encoder.encode(session.id), session.cookie.discard, true)
+ elseif storage.close then
+ storage:close(session.encoder.encode(session.id))
+ end
+
+ session.id = session:identifier()
+ end
+
+ return default.modify(session, "save", close, key(session))
+end
+
+return strategy