# Advanced Rules cache problems

**URL:** <https://community.openhab.org/t/advanced-rules-cache-problems/142589>\
**Category:** Scripts & Rules\
**Created:** [December 27, 2022, 6:34pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589 "2022-12-27T18:34:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![swissi](https://community.openhab.org/user_avatar/community.openhab.org/swissi/32/94973_2.png) [@swissi](https://community.openhab.org/u/swissi)\
**Post date:** [December 27, 2022, 6:34pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/1 "2022-12-27T18:34:22Z")

</div>

- Platform information:
  - Hardware: Intel(R) Atom™ Processor E3940 @ 1.60GHz/MemTotal:7957800 kB; MemFree:694920 kB/Avail: 158G
  - OS: Linux habpower3 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86\_64 x86\_64 x86\_64 GNU/Linux + Docker version 20.10.17, build 100c70180f
  - openHAB version: 3.4.0

Scripts installet:  
npm install openhab  
npm install openhab\_rules\_tools  
in automation/js with user and group 9001 (same for all Files)

I have Testet the Scripts on: [Rules - Advanced | openHAB](https://www.openhab.org/docs/tutorial/rules_advanced.html)

```javascript
console.info('Motion was detected');
items.getItem('FrontPorchLight').sendCommand('ON');

timerId = ruleUID+'_timer';
var lightsOut = function() {
  console.info('No more motion, turning off the light');
  items.getItem('FrontPorchLight').sendCommand('OFF');
  cache.put(timerId, null);
};

var timer = cache.get(timerId);
if(!timer) {
    cache.put(timerId, ScriptExecution.createTimer(time.ZonedDateTime.now().plusMinutes(30), lightsOut));
}
else {
    timer.reschedule(time.ZonedDateTime.now());
}

```

In the Script with cache.get und cache.put comes to the error:

```auto
org.graalvm.polyglot.PolyglotException: TypeError: undefined has no such function "get"
        at <js>.get(/openhab/conf/automation/js/node_modules/openhab/cache.js:34) ~[?:?]
        at <js>.:program(<eval>:31) ~[?:?]
        at org.graalvm.polyglot.Context.eval(Context.java:399) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426) ~[?:?]
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[java.scripting:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:53) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:74) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocableAndAutocloseable.eval(DelegatingScriptEngineWithInvocableAndAutocloseable.java:53) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.eval(InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java:74) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:71) ~[?:?]
        at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:68) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1180) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1031) ~[?:?]
        at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:328) ~[?:?]
        at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:342) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179) ~[bundleFile:3.4.5]
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) ~[bundleFile:3.4.5]
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201) ~[bundleFile:3.4.5]
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:104) ~[bundleFile:3.4.5]
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) ~[bundleFile:3.4.5]
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) ~[bundleFile:3.4.5]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:265) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:225) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:298) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:217) ~[bundleFile:3.4.5]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) ~[bundleFile:3.1.0]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:273) ~[bundleFile:3.4.5]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550) ~[bundleFile:9.4.46.v20220331]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:74) ~[bundleFile:?]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:600) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440) ~[bundleFile:9.4.46.v20220331]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:294) ~[bundleFile:?]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[bundleFile:9.4.46.v20220331]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:90) ~[bundleFile:?]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487) ~[bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) [bundleFile:9.4.46.v20220331]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) [bundleFile:9.4.46.v20220331]
        at java.lang.Thread.run(Thread.java:829) [?:?]
19:28:19.148 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'd454461be4' failed: org.graalvm.polyglot.PolyglotException: TypeError: undefined has no such function "get"

```

The Script “Open Reminder” make the same error.  
What am I doing wrong??

Peter

---

<div class="post-metadata">

**Author:** ![velibk](https://community.openhab.org/user_avatar/community.openhab.org/velibk/32/34515_2.png) [@velibk](https://community.openhab.org/u/velibk)\
**Post date:** [December 27, 2022, 8:04pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/2 "2022-12-27T20:04:51Z")

</div>

Hi Peter,  
Maybe you can want to read this topic,

[https://community.openhab.org/t/design-pattern-gate-keeper/36483/97?u=velibk](https://community.openhab.org/t/design-pattern-gate-keeper/36483/97)

> [@Design Pattern: Gate Keeper](https://community.openhab.org/t/design-pattern-gate-keeper/36483/97):
>
> Since you are running a version of OH prior to this past week, you’ll have to use the `cache` to save your Gatekeeper between runs of the rule, if you are creating rules in the UI.
> 
> ```auto
> var gk = cache.get(ruleUID+'_gk', () => new gatekeeper.Gatekeeper());
> 
> ```
> 
> In any version of OH past 3.4 M5 you’ll use the `privateCache` or `sharedCache` which I believe will look something like this:
> 
> ```auto
> var { privateCache } = require('@runtime');
> 
> var gk = privateCache.get(ruleUID+'_gk', () => new gatekeeper.Gatekeeper());
> 
> ```

and this reply,

> [@Design Pattern: Gate Keeper](https://community.openhab.org/t/design-pattern-gate-keeper/36483/103):
>
> You are on the Milestone 6.  
> This is older than the 3.4.0 Release.
> 
> If you are on the release, the build string would say something like **Release Build**.

---

<div class="post-metadata">

**Author:** ![florian-h05](https://community.openhab.org/user_avatar/community.openhab.org/florian-h05/32/117524_2.png) [@florian-h05](https://community.openhab.org/u/florian-h05)\
**Post date:** [December 27, 2022, 8:17pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/3 "2022-12-27T20:17:15Z")

</div>

@swissi Are you sure you have the latest version of the JavaScript library installed?

---

<div class="post-metadata">

**Author:** ![swissi](https://community.openhab.org/user_avatar/community.openhab.org/swissi/32/94973_2.png) [@swissi](https://community.openhab.org/u/swissi)\
**Post date:** [December 27, 2022, 8:44pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/4 "2022-12-27T20:44:14Z")

</div>

> [@Design Pattern: Gate Keeper](https://community.openhab.org/t/design-pattern-gate-keeper/36483/97):
>
> `var { privateCache } = require('@runtime');`

Thx for the fast anser rlkoshak.

privateCache don’t help with the Problem.

I have no Milestone:  
 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/e/1/e153247eb6bda4ee73d28e65312b49dd9adac127.png)

---

<div class="post-metadata">

**Author:** ![swissi](https://community.openhab.org/user_avatar/community.openhab.org/swissi/32/94973_2.png) [@swissi](https://community.openhab.org/u/swissi)\
**Post date:** [December 27, 2022, 8:48pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/5 "2022-12-27T20:48:15Z")

</div>

florian-h05

how can i check my installed library?

---

<div class="post-metadata">

**Author:** ![florian-h05](https://community.openhab.org/user_avatar/community.openhab.org/florian-h05/32/117524_2.png) [@florian-h05](https://community.openhab.org/u/florian-h05)\
**Post date:** [December 27, 2022, 8:51pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/6 "2022-12-27T20:51:06Z")

</div>

Go to the `automation/js` folder and then run: `cat node_modules/openhab/package.json`.

---

<div class="post-metadata">

**Author:** ![swissi](https://community.openhab.org/user_avatar/community.openhab.org/swissi/32/94973_2.png) [@swissi](https://community.openhab.org/u/swissi)\
**Post date:** [December 27, 2022, 8:57pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/7 "2022-12-27T20:57:14Z")

</div>

Version: 2.1.1  
On the github is 3.1.2

How can i upgrade to 3.1.2?

```auto
npm update openhab

```

This command don’t work.  
Or do I have to do this like this:

```auto
npm i git+https://github.com/openhab/openhab-js.git

```

---

<div class="post-metadata">

**Author:** ![florian-h05](https://community.openhab.org/user_avatar/community.openhab.org/florian-h05/32/117524_2.png) [@florian-h05](https://community.openhab.org/u/florian-h05)\
**Post date:** [December 27, 2022, 9:11pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/8 "2022-12-27T21:11:02Z")

</div>

> [@swissi](#):
>
> Version: 2.1.1

Explains everything …

> [@swissi](#):
>
> How can i upgrade to 3.1.2?

If you don‘t need type definitions, I‘d recommend to uninstall the library from the `node_modules` with `npm rm openhab`.  
Then you will use the version included in the addon, which is always is up-to-date and working with your openHAB version and you don‘t need to manually update it.

---

<div class="post-metadata">

**Author:** ![swissi](https://community.openhab.org/user_avatar/community.openhab.org/swissi/32/94973_2.png) [@swissi](https://community.openhab.org/u/swissi)\
**Post date:** [December 27, 2022, 9:13pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/9 "2022-12-27T21:13:09Z")

</div>

Ok, running the code directly in js is not possible:

```auto
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/openhab/openhab-js.git
npm ERR! No user exists for uid 9001
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-12-27T21_01_02_331Z-debug-0.log

```

But i make a tmp dir an then move from the tmp dir to the js dir.  
No is ok but the info is now:

```auto
22:07:41.818 [WARN] [enhab.automation.script.ui.88d16f8d44] - "cache.put" has been deprecated and will be removed in a future release. Use "cache.private.put" or "cache.shared.put" instead. Visit the JavaScript Scripting Automation addon docs for more information about the cache.

```

cache.put and get will be removed soon.

Thx for the help

---

<div class="post-metadata">

**Author:** ![swissi](https://community.openhab.org/user_avatar/community.openhab.org/swissi/32/94973_2.png) [@swissi](https://community.openhab.org/u/swissi)\
**Post date:** [December 27, 2022, 9:17pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/10 "2022-12-27T21:17:02Z")

</div>

> [@florian-h05](#):
>
> If you don‘t need type definitions, I‘d recommend to uninstall the library from the `node_modules` with `npm rm openhab`.  
> Then you will use the version included in the addon, which is always is up-to-date and working with your openHAB version and you don‘t need to manually update it.

In the addon?  
JRule?  
JavaScript Scripting?

---

<div class="post-metadata">

**Author:** ![florian-h05](https://community.openhab.org/user_avatar/community.openhab.org/florian-h05/32/117524_2.png) [@florian-h05](https://community.openhab.org/u/florian-h05)\
**Post date:** [December 27, 2022, 9:23pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/11 "2022-12-27T21:23:09Z")

</div>

Sou you have `openhab` version 2.1.1 in your `automation/js` folder, this version is very outdated.  
You need version 3.1.2 or newer for full compatibility with openHAB 3.4.

You now have two options:

a. Install the latest version in the `automation/js` folder  
b. Remove the manually `openhab` from `automation/js`

If you do not write JS rules in files and only use JS Scripting in the UI, I‘d recommend to remove the manually installed version. You do NOT need to have `openhab` installed inside `automation/js` to use it — a version of it is included inside the JS Scripting add-on.

Next, I am wondering why your files in the `automation/js` folder have user and group 9001. This doesn‘t seem right to me.

---

<div class="post-metadata">

**Author:** ![swissi](https://community.openhab.org/user_avatar/community.openhab.org/swissi/32/94973_2.png) [@swissi](https://community.openhab.org/u/swissi)\
**Post date:** [December 27, 2022, 9:40pm UTC](https://community.openhab.org/t/advanced-rules-cache-problems/142589/12 "2022-12-27T21:40:53Z")

</div>

2.1.1 **Closed** on Nov 12 this is old but not very outdated

I removed openhab from automation/js

User and Group 9001 is from the Docker.

Thx for the Help
