Changeset

1259:fa7e402fcdc1

mod_storage_memory: Simple in-memory only storage backend without persistence
author Kim Alvefur <zash@zash.se>
date Tue, 31 Dec 2013 02:17:50 +0100
parents 1258:fc82d8eded7d
children 1260:4e14ad802d58
files mod_storage_memory/mod_storage_memory.lua
diffstat 1 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_storage_memory/mod_storage_memory.lua	Tue Dec 31 02:17:50 2013 +0100
@@ -0,0 +1,36 @@
+
+local memory = setmetatable({}, {
+	__index = function(t, k)
+		local store = module:shared(k)
+		t[k] = store;
+		return store;
+	end
+});
+
+local keyval_store = {};
+keyval_store.__index = keyval_store;
+
+function keyval_store:get(username)
+	return self.store[username];
+end
+
+function keyval_store:set(username, data)
+	self.store[username] = data;
+	return true;
+end
+
+local stores = {
+	keyval = keyval_store;
+}
+
+local driver = {};
+
+function driver:open(store, typ)
+	local store_mt = stores[typ or "keyval"];
+	if store_mt then
+		return setmetatable({ store = memory[store] }, store_mt);
+	end
+	return nil, "unsupported-store";
+end
+
+module:provides("storage", driver);