Forum Discussion

saideepak's avatar
saideepak
Contributor
6 years ago

User cache/Cookie

i am looking to use User cache (set some value) in page init script and access that value in component by using user cache. Is it possible to do that?

<page init script> 

usercache.put("ksd", "1");

in custom component

usercache.get("ksd")

is this allowed?

if not, what is the way to achieve this? 

My requirement is "open the modal dialogue in first instance when user visits my website and then never show that window again?

  • saideepak I don't see a reason why this shouldn't work, but you might be better off setting a cookie in the page init script, see here, look for http.request.createCookie("name", "value"). The default usercache expiry time is much shorter (and harder to control because you need support for that) than with a cookie, plus you'll have to execute that logic constantly in the page init script, which you want to keep as "clean" as possible, e.g. you don't want to pack more logic than absolutely necessary in there (can make your page loads even slower than they already are out of the box).

    Another option I tend to use for more "temporary" stuff are session attributes, you can set them in the page init as well and use them later on.