Sometimes it's neccessary to store information that doesn't quite fit to be stored in properties on each page nor in the config files. Data that changes a lot or complicated object structures that is hard to match into a relational database.

KalikoCMS enables this by introducing DataStore which can be described as a dynamic object store. All objects that are serializable are also possible to store in the data store.

All pages in the system has a custom data store available called PageDataStore. This allow storing page specific information without using the page´s properties but the stored data is still unique to the current page.

If you wish to store data across pages a custom DataStore should be used instead.

Data stores can also be shared from anywhere in the code by giving them an ID or unique string as key. This makes it ideal to use to share information between pages. You'll get a custom DataStore by calling the DataStoreManager.GetStore(string key) function, passing the name of your DataStore as the key or DataStoreManager.GetStore(Guid id) where id is a Guid of your choice.

Simple PageDataStore example

This example stores a custom object that is used to count page accesses. Not the most useful function in the world, but simple enough to describe the core principles.

public partial class MyPage : PageTemplate<MyPageType> {

    // Define the object we want to save
    public class TestClass {
        public string Name;
        public int Count;
    }

    protected void Page_Load(object sender, EventArgs e) {
        // Try to get an object named "MyTest" for the current page
        TestClass test = PageDataStore.Get<TestClass>("MyTest");

        // Check if we have an object otherwise create one
        if (test == null) {
            test = new TestClass() { Name="A simple counter", Count = 0};
        }

        // Write to output stream and increase Count by one
        Response.Write(test.Name + "=" + test.Count);
        test.Count++;

        // Store the updated object
        PageDataStore.Store("MyTest", test);
    }

}

If you're using ASP.NET MVC or wish to read/write the page specific data store from other places than the page template you can do this by getting the data store for a particular page:

var pageDataStore = DataStoreManager.GetStore(currentPage);

 // Try to get an object named "MyTest" for the current page
 var test = pageDataStore.Get<TestClass>("MyTest");

 // Check if we have an object otherwise create one
 if (test == null) {
 test = new TestClass() { Name = "A simple counter", Count = 0 };
 }

 // Write to output stream and increase Count by one
 test.Count++;

 // Store the updated object
 pageDataStore.Store("MyTest", test);

Extensability

Since there are plenty of competent NoSQL products on the market Kaliko CMS has chosen a provider based approach. The default implementation uses the same data provider as the rest of the system, in other words Microsoft SQL Server, MySQL, SQLite or any other supported database system.

There's an additional implementation towards RaptorDB which also acts as a sample implementation if you wish to integrate against any other solution (such as MongoDB, RavenDB etc). If your website needs to do alot of updates of the data store content you should step away from the default implementation and select a NoSQL based provider but in many cases the standard version will do.