Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chakrit/rambase
RAM-based barely-transactional database which lets you forget about persistence for a (very) big while.
https://github.com/chakrit/rambase
Last synced: about 21 hours ago
JSON representation
RAM-based barely-transactional database which lets you forget about persistence for a (very) big while.
- Host: GitHub
- URL: https://github.com/chakrit/rambase
- Owner: chakrit
- Created: 2011-09-27T06:08:32.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2011-09-29T12:35:52.000Z (about 13 years ago)
- Last Synced: 2024-11-06T15:54:48.059Z (9 days ago)
- Language: C#
- Homepage:
- Size: 1.28 MB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
RAM-based barely-transactional C# database which lets you forget about
persistence for a (very) big while.What you need to do to use RAMbase is to create a class that contains all
of your models and mark it as `[Serializable]`.[Serializable]
public class Root {
public IList Users { get; private set; }
public IList BlogPosts { get; private set; }
}Then surround your model-accessing code with
using (var ctx = RAM.CreateContext())
using (var scope = ctx.CreateReadScope()) {// do non-modifying stuff with your model
}
or
using (var ctx = RAM.CreateContext())
using (var scope = ctx.CreateWriteScope()) {// modify your model
}
The above `using` blocks ensure that you're not incorrectly writing to the
model from multiple threads resulting in inconsistent model state. Internally,
a `ReaderWriterLockSlim` is used.RAMBase is actually a product of my frustration over having to install and
setup large relational databases (or any NoSQL for that matter) just to store
a small set of data.Some projects just calls for a simple file-based persistence with all data
loaded into the RAM at runtime. Sure, you could throw in some JSON
serialization love or `BinaryFormatter` for its simplicity but why do that
time and time again? Just throw in `RAMBase` and forget about persistence
until your project gets really big.# DOCS
By default RAMbase will try to persist your model to disk every 2 seconds after
a write or a read at the system's temp folder using the `BinaryFormatter`
(may change to custom serializer in the future -- I already have a working
implementation in several projects but it may not be generic enough).To customize how RAMbase works, instead of creating a new context directly,
use the `Configure()` method instead:var settings = RAM
.Configure()
.PersistAt(@"C:\MyAppFolder")
.PersistMinSeconds(5);The above code will create a RAMbase `Settings` which saves data to
`C:\MyAppFolder` every 5 seconds (still needs a call into the context to
trigger the save) and then to obtain a new context, simply doLvar context = settings.CreateContext();
More features will be added in the future if it proves to be of interest.
If you have any questions or suggestions, feel free to ping me on twitter
[@chakrit](http://twitter.com/chakrit) or just shoot me an email.# TODO
If you find it interesting, a few points where I think might be good addition is:
* A better default persistence (I have one implementation using Reflection
which I might add to RAMbase in the future).
* More persistence choices. JSON, XML, protobuf, blah blah.
* Some transaction support. Atomic writes, never corrupts save file etc.
* Compact runtime support. Silverlight, WP7 etc.This code is PUBLIC DOMAIN. Use it however you want. Also, there is no
guarantee whatsoever of any use. Use it at your own risk.