Skip to content

Commit

Permalink
Merge pull request #31 from cryptlex/ahmad/set-cache-mode
Browse files Browse the repository at this point in the history
feat: added set cache mode function
  • Loading branch information
adnan-kamili authored May 23, 2024
2 parents 40ea260 + 6513800 commit 0129471
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion post-build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$base_url = "https://dl.cryptlex.com/downloads"
$lexactivator_version ="v3.27.1"
$lexactivator_version ="v3.28.0"
new-item -Name tmp -ItemType directory

$url = "$base_url/$lexactivator_version/LexActivator-Win.zip"
Expand Down
26 changes: 26 additions & 0 deletions src/Cryptlex.LexActivator/LexActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,32 @@ public static void SetDebugMode(uint enable)
}
}

/// <summary>
/// Enables or disables in-memory caching for LexActivator.
/// This function is designed to control caching behavior to suit specific application requirements.
/// Caching is enabled by default to enhance performance.
/// Disabling caching is recommended in environments where multiple processes access the same license on a
/// single machine and require real-time updates to the license state.
/// </summary>
/// <param name="enable">false or true to disable or enable logging.</param>
public static void SetCacheMode(bool enable)
{
int status;
uint enableFlag = enable ? (uint)1 : (uint)0;
if (LexActivatorNative.IsWindows())
{
status = IntPtr.Size == 4 ? LexActivatorNative.SetCacheMode_x86(enableFlag) : LexActivatorNative.SetCacheMode(enableFlag);
}
else
{
status = LexActivatorNative.SetCacheMode(enableFlag);
}
if (LexStatusCodes.LA_OK != status)
{
throw new LexActivatorException(status);
}
}

/// <summary>
/// In case you don't want to use the LexActivator's advanced
/// device fingerprinting algorithm, this function can be used to set a custom
Expand Down
6 changes: 6 additions & 0 deletions src/Cryptlex.LexActivator/LexActivatorNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public static bool IsWindows()
[DllImport(DLL_FILE_NAME, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int SetDebugMode(uint enable);

[DllImport(DLL_FILE_NAME, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int SetCacheMode(uint enable);

[DllImport(DLL_FILE_NAME, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern int SetCustomDeviceFingerprint(string fingerprint);

Expand Down Expand Up @@ -423,6 +426,9 @@ public static bool IsWindows()
[DllImport(DLL_FILE_NAME_X86, CharSet = CharSet.Unicode, EntryPoint = "SetDebugMode", CallingConvention = CallingConvention.Cdecl)]
public static extern int SetDebugMode_x86(uint enable);

[DllImport(DLL_FILE_NAME_X86, CharSet = CharSet.Unicode, EntryPoint = "SetCacheMode", CallingConvention = CallingConvention.Cdecl)]
public static extern int SetCacheMode_x86(uint enable);

[DllImport(DLL_FILE_NAME_X86, CharSet = CharSet.Unicode, EntryPoint = "SetCustomDeviceFingerprint", CallingConvention = CallingConvention.Cdecl)]
public static extern int SetCustomDeviceFingerprint_x86(string fingerprint);

Expand Down

0 comments on commit 0129471

Please sign in to comment.