# Cookie overflow?

**URL:** <https://www.ruby-forum.com/t/cookie-overflow/168898>\
**Category:** Rails\
**Created:** [May 27, 2009, 7:22am UTC](https://www.ruby-forum.com/t/cookie-overflow/168898 "2009-05-27T07:22:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 7:22am UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/1 "2009-05-27T07:22:35Z")

</div>

I altered a controller to use a session variable in place of an instance  
variable, and this happened

Status: 500 Internal Server Error  
ActionController::Session::CookieStore::CookieOverflow

In the docs, it does say:

“If you have more than 4K of session data […] pick another session  
store.”

What does the phrase “pick another session store” mean? My purpose in  
doing this is to keep track of a list assembled by the user. If the  
user then chooses a sort option, I need to sort the list as it exists.  
AFAIK there are no other ways to doing this. I know nothing about  
cookies; does matter how big they are?

And, of course, how can I solve my problem?

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 7:47am UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/2 "2009-05-27T07:47:00Z")

</div>

Hi,

Your sessions (by default in cookie) needs to be moved to Active record  
store or memcache store to fix this issue.

For Databased sessions:  
config.action\_controller.session\_store = :active\_record\_store  
You need to create the session table as below  
rake db:sessions:create  
rake db:migrate

OR  
For Memcache sessions:  
config.action\_controller.session\_store = :mem\_cache\_store  
Also you need to setup a mem cache server and configure it as below  
config.cache\_store = :mem\_cache\_store, ‘localhost’, ‘127.0.0.1:11211’,  
{:namespace =\> ‘myapp123’}

-NAYAK

On Wed, May 27, 2009 at 10:52 AM, Mk 27  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> store."
> 
> >

–

- NAYAK

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 9:45am UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/3 "2009-05-27T09:45:30Z")

</div>

On May 27, 6:45 am, NAYAK [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> Your sessions (by default in cookie) needs to be moved to Active record  
> store or memcache store to fix this issue.

True, although storing large amounts of data in the session is rarely  
a good idea.

Fred

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 10:37am UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/4 "2009-05-27T10:37:08Z")

</div>

On Wed, May 27, 2009 at 1:14 PM, Frederick C. \<  
removed\_email\_address@domain.invalid\> wrote:

> a good idea.
> 
> > config.action\_controller.session\_store = :mem\_cache\_store
> > 
> > > –  
> > > Posted viahttp://www.ruby-forum.com/.
> > 
> > –
> > 
> > - NAYAK

–

- NAYAK

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 12:24pm UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/5 "2009-05-27T12:24:00Z")

</div>

Yes, you should store simply an array of ID’s, not the entire objects.  
An ID (integer) is about 4 bytes or so from memory, so it won’t be  
terribly much information…

* * *

Learn: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)  
Last updated 20-May-09 (Rails, Basic Unix)  
Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Twitter: [http://twitter.com/random8r](http://twitter.com/random8r)

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 2:46pm UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/6 "2009-05-27T14:46:14Z")

</div>

Julian L. wrote:

> Yes, you should store simply an array of ID’s, not the entire objects.  
> An ID (integer) is about 4 bytes or so from memory, so it won’t be  
> terribly much information…

This seems a terrible flaw\* to me then: how am I supposed to store this  
kind of data? I cannot use a normal global, instance, or class variable  
as these could become confused if multiple users are accessing the  
service at once. Am I supposed to create a new, temporary per user  
database – and how would I do that?

I guess I could keep track of the search terms that produced the list  
instead of the list itself, then when a sort is selected, reapply the  
search and then sort.

\*but maybe not surprising considering the nature of the html/http beast.

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 2:59pm UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/7 "2009-05-27T14:59:15Z")

</div>

On May 27, 1:46 pm, Mk 27 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Why a per user database? this could be stored in the database  
completely normally.

Fred

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 2:48pm UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/8 "2009-05-27T14:48:10Z")

</div>

Vishwanath Nayak wrote:

> For Databased sessions:  
> config.action\_controller.session\_store = :active\_record\_store  
> You need to create the session table as below  
> rake db:sessions:create  
> rake db:migrate

Ah, I guess that would be the temporary db solution…maybe I’ll try  
this first.

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [May 27, 2009, 3:20pm UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/9 "2009-05-27T15:20:29Z")

</div>

Frederick C. wrote:

> On May 27, 1:46ï¿½pm, Mk 27 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > 
> 
> Why a per user database? this could be stored in the database  
> completely normally.
> 
> Fred

Then I will run into the same “simultaneous” user problem. And it is  
not data that needs to be kept. Let me flesh this out a bit, as I am  
sure other people have dealt with almost identical issues:

The database contains a list of music albums. The user can view a list  
of all of them, or they could see a list based on some search criteria  
(artist or category). I would like to elaborate on this to allow the  
existing list on view to become more highly customized, using drag and  
drop, deleting and adding chunks, etc.

By default, the list appears sorted alphabetically by title. But the  
user should also be able to re-sort the existing list based on another  
criteria – eg, album length in mb, release date, etc. So rather that  
just deliver the list as it is requested using an @instance variable,  
I’m keeping it in the session hash. This way, if they click “Sort by  
release date”, I know what they are looking at and want sorted.

AFAIK it looks like I have two options:

1)Move the session data from cookie to Active Record  
2)Use the session data to store the previous search terms rather than  
the whole list, meaning reproduce the list and sort it (which I guess is  
what I would have done if I had known there was such a tiny limit on the  
session store size – at 20-60 bytes per item, it does not take much of  
list to reach 4k. I was working on a “use memory not processor” bias.  
I guess that is backward?)

Opinions?

---

<div class="post-metadata">

**Author:** ![mk27](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mk27](https://www.ruby-forum.com/u/mk27)\
**Post date:** [March 24, 2010, 4:17pm UTC](https://www.ruby-forum.com/t/cookie-overflow/168898/10 "2010-03-24T16:17:56Z")

</div>

Julian L. wrote:

> Yes, you should store simply an array of ID’s, not the entire objects.  
> An ID (integer) is about 4 bytes or so from memory, so it won’t be  
> terribly much information…
> 
> * * *
> 
> Learn: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)  
> Last updated 20-May-09 (Rails, Basic Unix)  
> Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
> Twitter: [http://twitter.com/random8r](http://twitter.com/random8r)

How can I tell if my program is storing an array or the entire object?  
Where in the code should I look? The create\_sessions migration?
