When the call to cache.private.get is given a defaultSupplier, I expected that defaultSupplier would only be called if there was no entry in the cache, but it looks like it is called every time.
17:10:09.637[INFO] [openhab.event.RuleUpdatedEvent] - Rule 'scratchpad' has been updated.
17:10:11.533[INFO] [org.openhab.automation.jsscripting.rule.scratchpad] - cache null
17:10:11.535[INFO] [org.openhab.automation.jsscripting.rule.scratchpad] - function called
17:10:11.536[INFO] [org.openhab.automation.jsscripting.rule.scratchpad] - function called
17:10:11.538[INFO] [org.openhab.automation.jsscripting.rule.scratchpad] - id1 5
Then the second time:
17:20:10.591[INFO] [org.openhab.automation.jsscripting.rule.scratchpad] - cache 5
17:20:10.594[INFO] [org.openhab.automation.jsscripting.rule.scratchpad] - function called
17:20:10.598[INFO] [org.openhab.automation.jsscripting.rule.scratchpad] - id1 5
Ignoring for now that on the first run, the function is called twice, am I right that the function should not be called on the second run?
I don’t think we have enough information to know where to raise the issue in the first place.
Are you using managed rules or file based rules?
I ran the code above in scratchpad and can confirm the behavior.
Are you sure it’s the second TimerMgr or is it the first one?
Is the TimerMgr that gets returned and set to timers the one that gets saved to the cache, or is that instance the one that gets lost (losing any timers that may have been added to it on that first run)?
You can download the dist-without-license artefact from the PR checks:
Put the openhab.js into your node_modules, turn off Cache openHAB JavaScript Library Injection in the JS Scripting add-on settings, resave your script, and report if that fixes the issue.
Thanks for confirmation
I would recommend removing the openhab.js file and either go back to the add-on included library version or manually handle it through npm – I will push a new release with the bug fix soon.