Data store in cache

Hi, Is it possible to store data in the cache, that could be read any time in all the class during the session ?

Which kind of data and cache?

If you want to store stuff in the current session on the server side, I’m using something like this:

image.png

image.png

Data from database or some String value, in the current session. Perhaps “cache” wasn’t a good approach …

I guess the code above will help. note that the data in session is shared between tabs (you can use the main layout if you want some data “cached” per tab)

Yes this code will help me, thank you @observant-okapi . Sorry but what do you mean by “tabs” ?

He means browser tab. Each UI is associated to a browser tab, and each Session is usually associated with a user login. So there can be more than one browser tab/ui per user session.

e.g. if you open your website 3 times with the same browser, each page will be associated to the same session

If you’re in a Spring project you could use a VaadinSessionScope or UIScope bean to hold stuff, depending on your needs