Is caching logic available from a Script API?

I'd like to be able to get/set a cached value for a user, preferably with a configurable TTL.  Is there a way to do this from a Widget - either with Velocity or JavaScript?

(pseudo-code e.g.)

var accessToken = someApi.userCache.get("remote.service.access.token", null);

if (accessToken == null) {
 accessToken = generateAccessToken(currentUser);
 someApi.userCache.set("remote.service.access.token", accessToken, timespan(30, "minutes"));
}

Parents Reply
  • Gotcha. Yeah, the traditional approach for integrating an external service is to create a plugin that 1) communicates with the service, 2) caches what it needs to (using that caching API), and 3) exposes its own set of methods to script for widgets/themes/automations with IScriptedContentFragmentExtension and potentially even exposes methods via REST with IRestEndpoints. And this is probably still the best approach. The plugin can also make itself configurable in Administration in case it needs its own keys, connection strings, etc.

Children
No Data