Reputation: 565
How can I programmatically clear the DNN cache when I have updated a setting in one of my DNN modules?
I have the following code which checks if something is cached in DNN.
/// <summary>
/// Loads the Web Home Page Categories set up in ERP
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
/// <remarks>RB 2017-08-17
/// RB 2017-09-18: Added Caching so that the result is loaded from cache instead of calling the server again</remarks>
[AllowAnonymous]
[HttpPost]
public string GetWebHomePagePublishingCategories([FromBody] ParrotRequestBase requestData)
{
GlobalSettings GV = GetGlobalSettingsForCurrentUser(requestData.UserID, requestData.CompanyID);
string cacheKey = Constants.conWebHomePagesCacheKey; //"WebHomePagesCacheKey";
var cache = DataCache.GetCache(cacheKey);
if (cache == null)
{
var timeOut = 20 * Convert.ToInt32(Host.PerformanceSetting);
cache = m_PubCtrl.WebHomePageCategories(GV.Globalvars, requestData);
if (timeOut > 0 & cache != null)
{
DataCache.SetCache(cacheKey, cache, TimeSpan.FromMinutes(timeOut));
}
}
return cache.ToString();
}
Upvotes: 1
Views: 995
Reputation: 35554
You can use DataCache
class in DotNetNuke.Common.Utilities
DataCache.ClearCache();
//or
DataCache.ClearModuleCache(TabId);
There are a lot more "Clear..." methods, so check them out if one of them suits your needs.
Upvotes: 2