Cleaning up Session (Cookie Based)

I am using the default Cookie-Based Session in Rails 2.0.

I have accumulated the bad practice of adding:

session['seen_announcement_' + Date.today.to_s] = true

over the years.

No users have complained yet, but I am assuming that each user must have hundreds of seen_announcement_XXXXX in their cookies

I would like to write a script to clean their sessions of those keys. Yet, I am finding the following:

1) session is not Hash. I cannot use session.keys to list all the keys in session. How would I do this? I would like to dump out a session then sort through the keys and delete the proper ones.

2) session.delete actually deletes the entire session. There is no method for deleting each key in a session.

Please help me on out this.

On the other hand, how does this work. Do all session variables get submitted along with HTTP request each time a user loads a page? So this means the more I store in session the slower a request takes?

I am using the default Cookie-Based Session in Rails 2.0.

I have accumulated the bad practice of adding:

session['seen_announcement_' + Date.today.to_s] = true

over the years.

No users have complained yet, but I am assuming that each user must have hundreds of seen_announcement_XXXXX in their cookies

I would like to write a script to clean their sessions of those keys. Yet, I am finding the following:

1) session is not Hash. I cannot use session.keys to list all the keys in session. How would I do this? I would like to dump out a session then sort through the keys and delete the proper ones.

2) session.delete actually deletes the entire session. There is no method for deleting each key in a session.

Please help me on out this.

On the other hand, how does this work. Do all session variables get submitted along with HTTP request each time a user loads a page? So this means the more I store in session the slower a request takes?

With the cookie store, yes. Each response and request. Furthermore, if your cookie goes over maximum recommended sizes (i forget exactly how much) the browser is free to just ignore it.

Fred

So now that I have put a lot of variables in a user's cookie, how can I go about removing them?

Sharkie Landshark wrote:

So now that I have put a lot of variables in a user's cookie, how can I go about removing them?

I will even settle for the process of cleaning up an entire session removing up its data from cookies and starting from stcratch -- doing this from Rails and not by requiring my users to delete cookies from browser.

Sharkie Landshark wrote:

So now that I have put a lot of variables in a user's cookie, how
can I go about removing them?

I will even settle for the process of cleaning up an entire session removing up its data from cookies and starting from stcratch -- doing this from Rails and not by requiring my users to delete cookies from browser.

If you change the secret used by the cookie store that will invalidate
all the sessions (you will get a bunch of exceptions as rails will
think the cookies were tampered with though).

Fred