Action Module implementation details

I’m trying to understand how action modules actually work as the information I’ve gotten from the support team does not seem to align with my testing.

We’ve been trying to find a solution for our high M2M usage. We create tokens to call an API to fetch additional data to add to claims, and we cache those tokens in the action cache, but the cache hit ration is very low and we’re using a lot more M2M tokens than we’d expected.

It has been suggested that using Action Modules would help resolve - we’ve been told that they run on a separate smaller pool of resources and although they don’t have a cache API available to them you can just store the values as a var in the module (i.e. a global variable).

I have to admit to being a bit skeptical about that as the documentation does not talk about anything like that and if they’re running as separate compute resources wouldn’t that imply that a call to an action is a remote call and therefore pass-by-value rather than pass-by-reference? In my testing (admittedly with a limited number of logins), I see no evidence of the lifecycle of the module being different to the action, and objects I pass into an action appear to be pass-by-reference.

Before I refactor our token acquisition to use a module and try this caching in a global variable (which I will only really know if it works when it gets to prod), can anyone tell me if it’s really the case that modules run separately and this will help with M2M caching?

And if they are shared and separate from the actions, do I have to worry about concurrency?

Thanks,

Andrew