4

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.

VDWWD
  • 35,079
  • 22
  • 62
  • 79
Nanji Mange
  • 2,155
  • 4
  • 29
  • 63

1 Answers1

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");
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • I think `` means class. so if I have class object of class `Employee`, the method would be like `public void setCache(Employee value, string key)`. Please correct me if I am wrong. – Nanji Mange Nov 16 '16 at 05:30
  • It a [Generic Type Parameter](https://msdn.microsoft.com/nl-nl/library/0zk36dx2.aspx). It's there so you don't need to create a `getCache` for every class/datatype. – VDWWD Nov 16 '16 at 08:12
  • It's working now. Thank you. This is also good idea if some one have JSON data. This may be helpful to readers. If you have JSON data, you can create a JSON file in solution explorer and add and get data from it. I think this is also one of the way if there is limited data. Please let me know if this will create issue in DNN Stucture. – Nanji Mange Nov 16 '16 at 09:12
  • Hi, Can I set time duration(lifetime) for Cache(individual key)? – Nanji Mange Jan 12 '17 at 12:48
  • Probably yes, `setCache` has a lot of overloads, one of them being `DateTime AbsoluteExpiration` – VDWWD Jan 12 '17 at 12:52