In-memory database
The Eloquera DB supports databases
stored in memory.
In-memory databases are useful when a high speed data
processing required, within embedded environments and for volatile data storing
e.g. monitored data.
When connecting to the server or in the desktop mode, specify the 'inmemory'
option in the connection string, like below:
db = new DB("server=(local);password=;options=inmemory;");
The in-memory databases can be persisted between sessions
(in the normal database file):
db = new DB("server=(local);password=;options=inmemory,persist;");
The 'persist' option allows to preserve the in-memory
database on the disk upon db.Close() call.
This will create a database file on the disk. A user can open the database back
to the memory simply using db.OpenDatabase.
Usage example:
const string db_name = "InMemoryDatabaseTest";
var db = new DB("server=(local);password=;options=inmemory,persist;");
db.DeleteDatabase(db_name, true);
db.CreateDatabase(db_name); //create inmemory database
db.OpenDatabase(db_name);
db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;
db.Store(new A(){value =
1234});
int counter = 0;
var res =
db.ExecuteQuery("SELECT A");
foreach (var r in res)
{
A a =
r as A;
Assert.AreEqual(a.value,
1234);
counter++;
}
Assert.AreEqual(counter,
1);
db.Close();//preserve database to the disk
db = new DB("server=(local);password=;options=inmemory,persist;");
db.OpenDatabase(db_name);//get database from the disk to the memory
db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;
db.Store(new B() { value = "Some text here" });
counter = 0;
res = db.ExecuteQuery("SELECT A");
foreach (var r in res)
{
A a = r as A;
Assert.AreEqual(a.value,
1234);
counter++;
}
Assert.AreEqual(counter,
1);
counter = 0;
res = db.ExecuteQuery("SELECT B");
foreach (var r in res)
{
B b = r as B;
Assert.AreEqual(b.value,
"Some text here");
counter++;
}
Assert.AreEqual(counter,
1);

Please note that the free database version can create the
in-memory databases up to 1GB in size.
A developer should be aware of physical memory availability and avoid
overgrowing the database too big, as Windows swapping may severely degrade the
database's performance.