Mercurial > prosody-modules
comparison mod_storage_memory/mod_storage_memory.lua @ 2619:1e4bbff0a6fd
mod_storage_memory: Add :purge() method to all store types
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 14 Mar 2017 12:59:41 +0000 |
| parents | a347b71adb07 |
| children | 8b8cab2eb7fc |
comparison
equal
deleted
inserted
replaced
| 2618:c6652d055ba3 | 2619:1e4bbff0a6fd |
|---|---|
| 6 return store; | 6 return store; |
| 7 end | 7 end |
| 8 }); | 8 }); |
| 9 | 9 |
| 10 local NULL = {}; | 10 local NULL = {}; |
| 11 | |
| 12 local function _purge_store(self, username) | |
| 13 self.store[username or NULL] = nil; | |
| 14 return true; | |
| 15 end | |
| 11 | 16 |
| 12 local keyval_store = {}; | 17 local keyval_store = {}; |
| 13 keyval_store.__index = keyval_store; | 18 keyval_store.__index = keyval_store; |
| 14 | 19 |
| 15 function keyval_store:get(username) | 20 function keyval_store:get(username) |
| 18 | 23 |
| 19 function keyval_store:set(username, data) | 24 function keyval_store:set(username, data) |
| 20 self.store[username or NULL] = data; | 25 self.store[username or NULL] = data; |
| 21 return true; | 26 return true; |
| 22 end | 27 end |
| 28 | |
| 29 keyval_store.purge = _purge_store; | |
| 23 | 30 |
| 24 local map_store = {}; | 31 local map_store = {}; |
| 25 map_store.__index = map_store; | 32 map_store.__index = map_store; |
| 26 | 33 |
| 27 function map_store:get(username, key) | 34 function map_store:get(username, key) |
| 52 if v == self.remove then v = nil; end | 59 if v == self.remove then v = nil; end |
| 53 userstore[k] = v; | 60 userstore[k] = v; |
| 54 end | 61 end |
| 55 return true; | 62 return true; |
| 56 end | 63 end |
| 64 | |
| 65 map_store.purge = _purge_store; | |
| 57 | 66 |
| 58 local archive_store = {}; | 67 local archive_store = {}; |
| 59 archive_store.__index = archive_store; | 68 archive_store.__index = archive_store; |
| 60 | 69 |
| 61 function archive_store:append(username, key, value, when, with) | 70 function archive_store:append(username, key, value, when, with) |
| 142 self.store[username or NULL] = nil; | 151 self.store[username or NULL] = nil; |
| 143 end | 152 end |
| 144 return true; | 153 return true; |
| 145 end | 154 end |
| 146 | 155 |
| 156 archive_store.purge = _purge_store; | |
| 157 | |
| 147 local stores = { | 158 local stores = { |
| 148 keyval = keyval_store; | 159 keyval = keyval_store; |
| 149 map = map_store; | 160 map = map_store; |
| 150 archive = archive_store; | 161 archive = archive_store; |
| 151 } | 162 } |
