Numerous are the times that I wanted to do this while working in a Sitecore project:
Something["LastIDProcessed"] = 50;
Where this ‘Something’ would persist my data in a way that I could always access it even after clearing cache, deploying or resetting IIS.
The first argument that comes to my mind against it is that I can create a new template in Sitecore and use it to store such data. True and I’m planning to do it soon :-). But I wanted something simpler than having to create templates, folders, keep track of the storage location under Sitecore tree, manage the publishing, make sure users can’t see my data etc… There are many steps do when implementing this inside the Sitecore tree.
I wanted a way to store my data directly to the DB in the fastest way with the least overhead processing. So I created SitecoreDynamicStorage.
What is it?
It is a library that allows storing Key-Value string data to core DB while making use of caching and event handling for better usage.
Sitecore.Context.Site.SetDynamicStorageValue("TypeStringKey", "This is a string"); string typeString = Sitecore.Context.Site.GetDynamicStorageValue("TypeStringKey");
- Dynamic naming: Sitecore.Context.Site.SetDynamicStorageValue(“whateverkeynameyouwant”, “value”)
- Be careful about this, it is usually not the best practice (because if you misspell the key, you will not get a build error but a runtime one or a bug that will not crash anything but result in incorrect results) but it could be useful sometimes and needed to dynamically manipulate data with dynamic names and values
- Data gets persisted to core DB so you don’t have to worry about clearing cache or resetting IIS
- Data gets cached after first retrieval until it gets updated again
- Availability of Event subscriptions to allow you to get notified on Added, Updated or Retrieved events
- Availability of a DynamicModel in which you can create a model with properties that get saved and retrieved from the core DB. This is used to overcome the dynamic typing and naming nature of this module
- Execute the ‘CreateTableScript.sql’ on Sitecore’s core DB
- Make sure the core DB connection string’s name is ‘core’ otherwise edit the connection string’s name in ‘SitecoreDynamicStorage.DataAccess.DynamicStorage.designer.cs’ from “core” to your connection string’s name.
- Update lib/Sitecore.Kernel.dll to the version you’re using (Sitecore DLL is not essential, used only for the Sitecore.Context.Site extension, so you can get rid of it of you prefer to)
- You will only have to add a reference to ‘SitecoreDynamicStorage.Core’ in your project
- Currently it supports string, int32, long and Datetime types but you can add more types by editing SitecoreDynamicStorage.Core.Extensions.DynamicStorageExtensions and in case you’re using the DynamicModel, SitecoreDynamicStorage.Core.DynamicModel
- To achieve ‘Something[“LastIDProcessed”] = 50;’, you’ll have to create your own indexer that access the SitecoreDynamicStorage.Core.Extensions.DynamicStorageExtensions methods
- Currently doesn’t work on CM-CD configuration with multiple core DBs