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

How to clear DNN cache after a setting has been changed in a custom module

当我更新了其中一个 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();
}

您可以在DotNetNuke.Common.Utilities

中使用DataCacheclass
DataCache.ClearCache();
//or
DataCache.ClearModuleCache(TabId);

还有很多 "Clear..." 方法,如果其中一种适合您的需要,请查看它们。