Skip to content

Commit

Permalink
Improve SyncronizeCache.
Browse files Browse the repository at this point in the history
Avoid looping twice through all modules
  • Loading branch information
Robrecht Siera committed Apr 5, 2019
1 parent 8503a76 commit 1df8d94
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
50 changes: 46 additions & 4 deletions OpenContent/Components/Caching/DnnCacheAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Entities.Modules;
Expand All @@ -9,6 +6,9 @@
using DotNetNuke.Services.Cache;
using DotNetNuke.Services.ModuleCache;
using DotNetNuke.Services.OutputCache;
using System;
using System.Collections;
using System.Collections.Generic;

namespace Satrabel.OpenContent.Components
{
Expand Down Expand Up @@ -62,10 +62,52 @@ private static void SyncronizeLinkedModules(int portalId, int dataModuleId)
foreach (var ocModule in ocModules)
{
if (ocModule.DataModule.ModuleId == dataModuleId)
SynchronizeModule(ocModule.ViewModule.ModuleId);
SynchronizeViewModule(ocModule.ViewModule.ModuleInfo);
}
}

/// <summary>
/// Synchronizes the cache.
/// </summary>
/// <remarks>
/// Based on DNN SynchronizeModule(int moduleID)
/// </remarks>
private static void SynchronizeViewModule(ModuleInfo module)
{
DataProvider dataProvider = DataProvider.Instance();
//IList<ModuleInfo> modules = ModuleController.Instance.GetTabModulesByModule(moduleId);

Hashtable tabSettings = TabController.Instance.GetTabSettings(module.TabID);
if (tabSettings["CacheProvider"] != null && tabSettings["CacheProvider"].ToString().Length > 0)
{
var outputProvider = OutputCachingProvider.Instance(tabSettings["CacheProvider"].ToString());
outputProvider?.Remove(module.TabID);
}

if (module.CacheTime > 0)
{
var cachingProvider = ModuleCachingProvider.Instance(module.GetEffectiveCacheMethod());
cachingProvider?.Remove(module.TabModuleID);
}

//Synchronize module is called when a module needs to indicate that the content
//has changed and the cache's should be refreshed. So we can update the Version
//and also the LastContentModificationDate
dataProvider.UpdateTabModuleVersion(module.TabModuleID, Guid.NewGuid());
dataProvider.UpdateModuleLastContentModifiedOnDate(module.ModuleID);

////We should also indicate that the Transalation Status has changed
//if (PortalController.GetPortalSettingAsBoolean("ContentLocalizationEnabled", module.PortalID, false))
//{
// ModuleController.Instance.UpdateTranslationStatus(module, false);
//}

// and clear the cache
ModuleController.Instance.ClearCache(module.TabID);

}


/// <summary>
/// Synchronizes the cache.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenContent/Components/OpenContentAPIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public HttpResponseMessage Update(JObject json)
{
ds.Update(dsContext, dsItem, json["form"] as JObject);
}
//App.Services.CacheAdapter.SyncronizeCache(module);
App.Services.CacheAdapter.SyncronizeCache(module);
}
catch (DataNotValidException ex)
{
Expand Down

0 comments on commit 1df8d94

Please sign in to comment.