Mercurial > prosody-modules
annotate mod_storage_memory/mod_storage_memory.lua @ 1555:2e51f70cd7ea
mod_http_muc_log: Make pretty
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 09 Nov 2014 08:38:57 +0100 |
parents | fa7e402fcdc1 |
children | 8b997d9cf09e |
rev | line source |
---|---|
1259
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local memory = setmetatable({}, { |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 __index = function(t, k) |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local store = module:shared(k) |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 t[k] = store; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 return store; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 }); |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local keyval_store = {}; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 keyval_store.__index = keyval_store; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 function keyval_store:get(username) |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 return self.store[username]; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 function keyval_store:set(username, data) |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 self.store[username] = data; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 return true; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 local stores = { |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 keyval = keyval_store; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 } |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 local driver = {}; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 function driver:open(store, typ) |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 local store_mt = stores[typ or "keyval"]; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 if store_mt then |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 return setmetatable({ store = memory[store] }, store_mt); |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 return nil, "unsupported-store"; |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 |
fa7e402fcdc1
mod_storage_memory: Simple in-memory only storage backend without persistence
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 module:provides("storage", driver); |