We saw in the first cookie example, how we assigned a special erlang process to handle each session. The cookie has an expiry date, and the correct thing would be to let the handling process live as long as the cookie is valid. This is not a good option. A better option is to store cookie in a persistant storage. This can be an ets table or a dets table. If we choose an ets table, the cookies will disappear when the yaws server is restarted, whereas if we choose a dets table, the cookies will survive daemon restarts. What to choose depends on the type of cookie information we have.
The yaws code in setpcookie.yaws sets the cookie in the browser.
And the yaws code in readpcookie.yaws will read the cookie
Let's show some code. To set the cookie we we have:
And to read the cookie, we have the following code: