Rule DSL: The name 'sharedCache' cannot be resolved to an item or type

Hi,

I’m trying to store a global variable in sharedCache according to the official documentation (https://www.openhab.org/docs/configuration/rules-dsl). However the rules engine complains:

Script execution of rule with UID 'Startup-1' failed: The name 'sharedCache' cannot be resolved to an item or type; line 5, column 8, length 11 in Startup

Below is my rule:

rule "Edit the Xiaomi.things to make the sub-devices online"
    when System reached start level 100 
then
    if(sharedCache.get("SystemStarted") == null){
        executeCommandLine("../conf/rules/Startup.sh")
        sharedCache.put("SystemStarted", "true")
    } 
end

I’m running OH 4.2 stable version, is this feature removed? Or maybe the implicate variable renamed?

It’s not been removed and I’m fact I don’t think anything has changed in the cache between 4.1 and 4.2.

The docs still say it should be there.

I can’t imagine the sharedCache isn’t available by run level 100. If you run the rule manually do you still get the error?

1 Like

Thank for your reply!
I also tried to trigger the rule by cron and same result. In visual studio code it also highlights the variable name cannot be found. Maybe it’s renamed?

Edit: also tried cache.shared without luck, I got the same error.
Neither 4.2.0 nor 4.2.1 work for me. It’s the first time I try to use the shared cache so I don’t know if it worked in previous versions.

That’s the JS Scripting syntax.

I’m order to narrow down the problem:

  • is this the only role that has the problem?
  • can you access the cache from another language (e.g Blockly?)

What do you mean by only role?

auto correct and myopia are the bane of my existence. “rule”

Ah ok, I tried to make some rules in other rules file with different trigger conditions, same result. Also tested with privateCache and OH complains it doesn’t exist. So it looks to me like DSL rules engine for some reason doesn’t inject those implicit variables when running the rules. (I have already done the usual suspects, like restart and clean cache)

Anybody who also experiences this issue with DSL rules?

I did not know about the cache before and found it quite handy for some of my rules.
Tried it without success (Openhab 4.2.1)

Thanks so looks like something must have changed in recent releases. The cache was introduced in OH 3.X I believe.

I can say it still works in JS Scripting so this must be something Rules DSL specific.

1 Like

I opened sharedCache broken for rules DSL · Issue #4447 · openhab/openhab-core · GitHub

1 Like