2

I've recently encountered cookieOverflow exception in my rails application. I've googled a bit and found this answer to be most helpful :

https://stackoverflow.com/a/9474262/169277

After having implemented storing sessions in database I'm trying to figure out the drawbacks of this approach so far I see around 1200 entries in sessions table which was populated in only few hours.

When does actual interaction with database occurs, only when writing data to session or?

This grows rather fast so is there a way to purge old unused sessions from db other than having some daily cron jobs or something.

I'm just looking some additional information regarding this approach, right now I'm thinking should I keep it or change logic of my app.

Community
  • 1
  • 1
Gandalf StormCrow
  • 25,788
  • 70
  • 174
  • 263

1 Answers1

1

> 4KB in a cookie is a lot, so changing your app is probably not a bad idea to consider.

That said, 1200 in a few hours doesn't seem outlandish. If you're worried about growing it unbounded, you can use memcache or redis as a caching layer to store your cookies instead of your database. That would free you from worrying about growth in your database. The downside is that evictions probably mean that you're logging people out.

All that said, we have a number of daily cron-like jobs that clean out our database tables, not for sessions, but it's similar. They run at night when utilization is low anyway.

John Hinnegan
  • 5,864
  • 2
  • 48
  • 64