How to store data temporarily in DotnetNuke 7?

∥☆過路亽.° 提交于 2019-12-10 16:46:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!