Comparison

plugins/mod_storage_memory.lua @ 9839:9007ae90aeb1

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 02 Mar 2019 22:26:30 +0100
parent 9834:a657df70cc31
parent 9838:40ed04014b97
child 9882:18f025b3987d
comparison
equal deleted inserted replaced
9837:789395f027f1 9839:9007ae90aeb1
1 local serialize = require "util.serialization".serialize; 1 local serialize = require "util.serialization".serialize;
2 local array = require "util.array"; 2 local array = require "util.array";
3 local envload = require "util.envload".envload; 3 local envload = require "util.envload".envload;
4 local st = require "util.stanza"; 4 local st = require "util.stanza";
5 local is_stanza = st.is_stanza or function (s) return getmetatable(s) == st.stanza_mt end 5 local is_stanza = st.is_stanza or function (s) return getmetatable(s) == st.stanza_mt end
6 local new_id = require "util.id".medium;
6 7
7 local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false); 8 local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false);
8 local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {}); 9 local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {});
9 10
10 local memory = setmetatable({}, { 11 local memory = setmetatable({}, {
62 a = {}; 63 a = {};
63 self.store[username or NULL] = a; 64 self.store[username or NULL] = a;
64 end 65 end
65 local v = { key = key, when = when, with = with, value = value }; 66 local v = { key = key, when = when, with = with, value = value };
66 if not key then 67 if not key then
67 key = tostring(a):match"%x+$"..tostring(v):match"%x+$"; 68 key = new_id();
68 v.key = key; 69 v.key = key;
69 end 70 end
70 if a[key] then 71 if a[key] then
71 table.remove(a, a[key]); 72 table.remove(a, a[key]);
72 end 73 end