Skip to content

Commit

Permalink
Merge pull request #67 from cryptlex/cachemode
Browse files Browse the repository at this point in the history
feat: add setCacheMode function
  • Loading branch information
ahmad-kemsan authored May 23, 2024
2 parents 9d45f52 + 53ca562 commit 9d9dbed
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/lexactivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LexActivatorNative } from "./lexactivator-native.js";
import { LexStatusCodes } from "./lexstatus-codes.js";
import { LexActivatorException } from "./lexactivator-exception.js";
import { arrayToString } from "./lexactivator-native.js";
import { Release } from "./release.js"
import { Release } from "./release.js";

/**
* @class LicenseMeterAttribute
Expand Down Expand Up @@ -214,6 +214,33 @@ export class LexActivator {
}
}

/**
* 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.
*
* @param {enable} true or false to enable or disable in-memory caching.
* @throws {LexActivatorException}
*/

static SetCacheMode(enable: boolean): void{
let enableFlag;
if(enable){
enableFlag = 1;
}
else{
enableFlag = 0;
}
const status = LexActivatorNative.SetCacheMode(enableFlag);
if (LexStatusCodes.LA_OK != status) {
throw new LexActivatorException(status);
}
}

/**
* 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
16 changes: 16 additions & 0 deletions src/native/LexActivator.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ LEXACTIVATOR_API int LA_CC SetDataDirectory(CSTRTYPE directoryPath);
*/
LEXACTIVATOR_API int LA_CC SetDebugMode(uint32_t enable);

/*
FUNCTION: SetCacheMode()
PURPOSE: 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.
* enable - 0 or 1 to disable or enable in-memory caching.
RETURN CODES: LA_OK, LA_E_PRODUCT_ID
*/

LEXACTIVATOR_API int LA_CC SetCacheMode(uint32_t enable);

/*
FUNCTION: SetCustomDeviceFingerprint()
Expand Down
17 changes: 17 additions & 0 deletions src/native/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ Napi::Value setDebugMode(const Napi::CallbackInfo &info)
return Napi::Number::New(env, SetDebugMode(arg0));
}

Napi::Value setCacheMode(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
if (info.Length() < 1)
{
Napi::TypeError::New(env, MISSING_ARGUMENTS).ThrowAsJavaScriptException();
return env.Null();
}
if (!info[0].IsNumber())
{
Napi::TypeError::New(env, INVALID_ARGUMENT_TYPE).ThrowAsJavaScriptException();
return env.Null();
}
uint32_t arg0 = info[0].As<Napi::Number>().Uint32Value();
return Napi::Number::New(env, SetCacheMode(arg0));
}

Napi::Value setCustomDeviceFingerprint(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Expand Down Expand Up @@ -1521,6 +1537,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
exports["SetProductData"] = Napi::Function::New(env, setProductData);
exports["SetDataDirectory"] = Napi::Function::New(env, setDataDirectory);
exports["SetDebugMode"] = Napi::Function::New(env, setDebugMode);
exports["SetCacheMode"] = Napi::Function::New(env, setCacheMode);
exports["SetCustomDeviceFingerprint"] = Napi::Function::New(env, setCustomDeviceFingerprint);
exports["SetProductId"] = Napi::Function::New(env, setProductId);
exports["SetLicenseKey"] = Napi::Function::New(env, setLicenseKey);
Expand Down

0 comments on commit 9d9dbed

Please sign in to comment.