Play Framework: Session's Gotchas
I've just switched our cookies to Play's Session. I was previously under the impression that "Session" is temporary, as in the stored value isn't persisted after the browser is closed.
After looking closely at it, Play's Session is implemented using a cookie, and we can simply set maxAge
in order to make it behave like a persisted cookie.
Here are the 2 gotchas:
play.http.session.maxAge
is of the typeFiniteDuration
. Therefore, in yourapplication.conf
, you would have to set it to something likeplay.http.session.maxAge="31536000s"
, not just31536000
.- You can use
addingToSession
andremovingFromSession
as the replacements forwithCookies
anddiscardCookies
.- Please note that
withSession
isn't a replacement forwithCookies
because it replaces the whole Session. It doesn't add like howwithCookies
adds new cookies to the current set of cookies.
- Please note that