如何在 DotnetNuke 7 中临时存储数据?

How to store data temporarily in DotnetNuke 7?

我是 DotnetNuke 的新手。请随意建议我正确的术语。 我正在研究 DotnetNuke 7。我使用 C#。我有一个包含 30 个字符串字段的 table,它最多可以有 50 条记录。目前我正在使用数据库管理它。

我认为数据不多,我应该将其存储在本地存储(如果有的话)中,这比从数据库中获取数据更快。

DotnetNuke 中是否有任何本地存储(临时)及其生命周期,有人可以建议我吗?

另外请建议我切换本地存储而不是数据库的想法。

您可以使用内置的 DNN 缓存功能。

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);
}

用法:

string myString = "test";
Book myBook = new Book();

setCache(myString, "A");
setCache(myBook, "B");

string myStringFromCache = getCache<string>("A");
Book myBookFromCache = getCache<Book>("B");