From 185c05e7428a01690ef3a506da9dc8b8e2a0a016 Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Thu, 22 May 2014 13:37:15 -0400 Subject: [PATCH] Fix issue #196: make memory provider DBs sharable --- src/providers/memory.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/providers/memory.js b/src/providers/memory.js index 38104e2..18c4ff9 100644 --- a/src/providers/memory.js +++ b/src/providers/memory.js @@ -1,8 +1,20 @@ define(function(require) { var FILE_SYSTEM_NAME = require('src/constants').FILE_SYSTEM_NAME; - var asyncCallback = require('async').nextTick; + /** + * Make shared in-memory DBs possible when using the same name. + */ + var createDB = (function() { + var pool = {}; + return function getOrCreate(name) { + if(!pool[name]) { + pool[name] = {}; + } + return pool[name]; + }; + }()); + function MemoryContext(db, readOnly) { this.readOnly = readOnly; this.objectStore = db; @@ -50,7 +62,7 @@ define(function(require) { function Memory(name) { this.name = name || FILE_SYSTEM_NAME; - this.db = {}; + this.db = createDB(this.name); } Memory.isSupported = function() { return true;