Backend variable is not persistent

I store a variable in my backend defined file:
const USER_CACHE = new Map();
but every request, the map is getting initialized again.
Why is that? The expected behaviour would be that it doesn’t get initialized again until restart or version upgrade.
I am using new Forge NodeJS environment.

This seems normal to me. Forge backend functions are built on top of AWS Lambda so they are essentially stateless. If you’re trying to build some kind of caching mechanism, I would suggest looking at the Cache API (currently in EAP).

2 Likes