How to add Items to the Cache Application Data on Server

How to add Items to the Cache Application Data on Server

Hi guys,

I need to save information on server cache to be accessible to all users of my application. I can't store this on Session, because other users won't be able to access it. 

Googling around I found the Caching Application Data of .NET, so I wondered to create an extension to it, but I had no success yet...

Any ideas?

Hi André,

Have you taken a look at Cache In Minutes property? It'll use the cache in memory for each Front-end, so it is not user session related. Will it work for your scenario?

Unfortunately it doesn't work for my scenario Pedro, just because the elements that can be cached are the following (below), and I need to store a text on the server memory to make it available externally (and for 10 sec) .
I'll try to explain it better: When my user log in my application, a key-token is generated and stored for 10 sec. This token will send only for registered domains that request an information. So anyone who makes a request to my app will need this key-token to be validated. If I store this key-token on the Session, external requests (like web services) will not be able to access it.

The good news is that I managed to implement an extension for this using the MemoryCache Class from .NET. I'll publish on the forge as soon as possible and post here the link.



Hummmm... couldn't the User-defined Action with a Text output parameter do that work for you?

Furthermore, you could have stored the key-token in an entity referencing UserId and with a DateTime attribute, being then (both) returned by the cached action, so you could control token expiration. I'm pretty sure this implementation (or similar approaches) has been done in lots of OutSystems projects before. But glad you made it on your own. Congrats!
Hello Andre. Just be careful when storing tokens in memory: it won't work in farm scenarios, because the token will be stored in only one of the nodes.

You should check if your solution should support a farm with two or more frontends. If so, the solution suggested by Pedro of storing the token on the database seems like a good alternative.
Good point Leo. You are right, I'll check if we have a farm scenario to avoid this behavior.

If so, I'll try the solution you suggested, Pedro. 

Finally I published the component in the forge:

Best regards,
André Siébra