问题
I am new in DotnetNuke. Feel free to suggest me correct terminology. I am working on DotnetNuke 7. I use C#. I have a table with 30 string fields and it can have maximum 50 records. Currently I am managing it using Database.
I think it's not much data and I should store it in local storage(if any) which can be faster than get data from database.
Can anybody suggest me if there is any local storage (temporary) and life of it in DotnetNuke?
Also please suggest me about my idea of switching over local storage rather database.
回答1:
You could use the build-in DNN cache functionality.
using DotNetNuke.Common.Utilities;
public bool cacheExists(string key)
{
return DataCache.GetCache(key) != null;
}
public void setCache<T>(T value, string key)
{
DataCache.SetCache(key, value);
}
public T getCache<T>(string key)
{
return (T)DataCache.GetCache(key);
}
Usage:
string myString = "test";
Book myBook = new Book();
setCache(myString, "A");
setCache(myBook, "B");
string myStringFromCache = getCache<string>("A");
Book myBookFromCache = getCache<Book>("B");
来源:https://stackoverflow.com/questions/40603288/how-to-store-data-temporarily-in-dotnetnuke-7