Skip to content

Commit

Permalink
updated cache options for bpmn xml file
Browse files Browse the repository at this point in the history
  • Loading branch information
besley committed Oct 21, 2024
1 parent 4c97a22 commit 02fb55e
Show file tree
Hide file tree
Showing 6 changed files with 420 additions and 409 deletions.
Binary file modified source/.vs/SfBpmn/v17/.suo
Binary file not shown.
773 changes: 389 additions & 384 deletions source/.vs/SfBpmn/v17/DocumentLayout.json

Large diffs are not rendered by default.

28 changes: 9 additions & 19 deletions source/lib/Slickflow.Engine/Config/WfConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,23 @@
namespace Slickflow.Engine.Config
{
/// <summary>
/// 流程参数配置列表
/// Workflow Configuration
/// </summary>
internal class WfConfig
{
private static readonly int _expiredDays = 1;
private static readonly string _externalServiceFile = "Plugin\\Slickflow.Module.External.dll";

/// <summary>
/// 获取过期时间设置参数
/// BPMN file cache expired days
/// </summary>
/// <returns></returns>
internal static int GetDefaultExpiredDays()
{
return _expiredDays;
}
internal static readonly int EXPIRED_DAYS = 1;

/// <summary>
/// 获取外部服务文件,加载
/// BPMN file cache enabled true/false
/// </summary>
/// <returns></returns>
internal static Assembly LoadExternalServiceFile()
{
var directory = AppDomain.CurrentDomain.BaseDirectory;
var serviceFile = Path.Combine(directory, _externalServiceFile);
var assembly = Assembly.LoadFrom(serviceFile);
internal static readonly bool EXPIRED_DAYS_ENABLED = false;

return assembly;
}
/// <summary>
/// Local Service File Path
/// </summary>
internal static readonly string EXTERNAL_SERVICE_FILE_PATH = "Plugin\\Slickflow.Module.External.dll";
}
}
6 changes: 5 additions & 1 deletion source/lib/Slickflow.Engine/Utility/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq.Expressions;
using Slickflow.Module.Localize;
using Slickflow.Engine.Config;
using System.IO;

namespace Slickflow.Engine.Utility
{
Expand All @@ -20,7 +21,10 @@ public static class ReflectionHelper
/// <returns>实例</returns>
public static T GetSpecialInstance<T>(string fullName) where T : class
{
var assembly = WfConfig.LoadExternalServiceFile();
var directory = AppDomain.CurrentDomain.BaseDirectory;
var serviceFile = Path.Combine(directory, WfConfig.EXTERNAL_SERVICE_FILE_PATH);
var assembly = Assembly.LoadFrom(serviceFile);

var list = assembly.GetTypes().Where(x => typeof(T).IsAssignableFrom(x)
&& !x.IsInterface
&& !x.IsAbstract
Expand Down
19 changes: 15 additions & 4 deletions source/lib/Slickflow.Engine/Xpdl/ProcessModelBPMN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Slickflow.Engine.Xpdl.Entity;
using Slickflow.Engine.Xpdl.Schedule;
using Slickflow.Engine.Xpdl.Node;
using Slickflow.Engine.Config;

namespace Slickflow.Engine.Xpdl
{
Expand All @@ -34,12 +35,22 @@ public Process Process
var processGUID = ProcessEntity.ProcessGUID;
var version = ProcessEntity.Version;

if (XPDLMemoryCachedHelper.GetXpdlCache(processGUID, version) == null)
if (WfConfig.EXPIRED_DAYS_ENABLED == true)
{
var process = ConvertProcessModelFromXML(ProcessEntity);
XPDLMemoryCachedHelper.SetXpdlCache(processGUID, version, process);
//Get Process content from cache
if (XPDLMemoryCachedHelper.GetXpdlCache(processGUID, version) == null)
{
var process = ConvertProcessModelFromXML(ProcessEntity);
XPDLMemoryCachedHelper.SetXpdlCache(processGUID, version, process);
}
return XPDLMemoryCachedHelper.GetXpdlCache(processGUID, version);
}
else
{
//Get Process content from database
var processDB = ConvertProcessModelFromXML(ProcessEntity);
return processDB;
}
return XPDLMemoryCachedHelper.GetXpdlCache(processGUID, version);
}
}
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion source/lib/Slickflow.Engine/Xpdl/XPDLMemoryCachedHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Slickflow.Engine.Config;
using Slickflow.Engine.Utility;
using Slickflow.Engine.Xpdl.Entity;

Expand All @@ -18,7 +19,7 @@ internal class XPDLMemoryCachedHelper
static XPDLMemoryCachedHelper()
{
var cacheOptions = new MemoryCacheOptions();
cacheOptions.ExpirationScanFrequency = TimeSpan.FromDays(1);
cacheOptions.ExpirationScanFrequency = TimeSpan.FromDays(WfConfig.EXPIRED_DAYS); //default days is 1
_xpdlCache = new MemoryCache(cacheOptions);
}

Expand Down

0 comments on commit 02fb55e

Please sign in to comment.