如何在自定义模块中更改设置后清除DNN缓存

时间:2018-04-23 14:41:52

标签: caching dotnetnuke

当我更新了某个DNN模块中的设置时,如何以编程方式清除DNN缓存?

我有以下代码检查是否在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();
}

1 个答案:

答案 0 :(得分:1)

您可以在DotNetNuke.Common.Utilities

中使用DataCache.ClearCache(); //or DataCache.ClearModuleCache(TabId); 课程
@SubscribeMapping("/reply")
public String initialReply() throws Exception {
    return "Welcome to the chat room.";
}

还有更多“清除...”方法,所以如果其中一个方法符合您的需要,请查看它们。