Actions api.cache entries not persisting across login runs

I am trying to use the actions cache to persist a token across login runs. The set operation returns success. The value is found in cache in later actions in the same flow. But when initiating a new login flow, the key is consistently not found in cache. Here is a simplified example (which also does not work):

// In action 1
exports.onExecutePostLogin = async (event, api) => {
  const cachedValue = api.cache.read('tst')?.value;
  console.log('cachedValue: ' + cachedValue);
  if (!cachedValue) {
     api.cache.set('tst', '1234');
  }
}
// In action 2
exports.onExecutePostLogin = async (event, api) => {
  const cachedValue = api.cache.read('tst')?.value;
  console.log('cachedValue: ' + cachedValue);
}

However many login flows I execute, I always just see “cachedValue: undefined” in the log for action 1, while in the log for action 2 I see “cachedValue: 123”.

Are the cache entries not supposed to persist across logins?

That is correct - Data from one Action is available to later Action(s) within the same flow only.

Then the documentation is very misleading.

From Actions Triggers: post-login - API Object

api.cache

Store and retrieve data that persists across executions.

It gets extra confusing when it says in Actions Limitations that

  • Cached items persist for a maximum of 24 hours.

and default ttl is 15 minutes.

That seems very long for single login flows, and makes this extra confusing.