Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How big of a cookie can/should I create?

When users log into our site we retrieve an object from our database that contains various settings that are used throughout the site. In order to reduce server load from going back to our database each time the user interacts with our site, we are trying to think of alternative ways. (We serialize and de-serialize the object, when needed). The object is likely to be <1MB but could vary.

  1. How big of an object can we have in a session without significantly affecting performance?
  2. How big of an object can we store in a cookie?
  3. Are there any other alternatives (other, than, retrieving the data from our DB)?
like image 416
user_78361084 Avatar asked Jan 03 '12 01:01

user_78361084


People also ask

How Big Should cookies be?

Well, take a look. That small cookie scoop is less than an ounce of dough and the baked cookie is about 2-inches in diameter. The medium cookie scoop is 1.25 ounces of dough and yields a 3-inch cookie. And that behemoth cookie scoop and it's 2.25 ounces of dough is going to give you a very hearty 4-inch cookie.

How Big Should cookies be before baking?

For softer, chewier cookies, bake for the shorter amount of time indicated in the recipe. When placing dough on cookie sheet, allow sufficient space between cookies, usually 1-1/2 to 2 inches unless recipe directs otherwise.

What is the best size for a chocolate chip cookie?

A medium cookie scoop, the Goldilocks size for most bakers, is often a #30 or #40, which dispense 2 tablespoons and 1.6 tablespoons of dough, respectively. I favor a medium-size scoop for my peanut butter, chocolate chip, gingerbread, and oatmeal raisin cookie needs.


1 Answers

The maximum allowed cookie size depends on the client. For example, a MSDN article from 2005 says that the whole cookie may have at least 4096 bytes available (including expiry date etc). The RFC mentioned in the same article contains some more information regarding limitations:

6.3 Implementation Limits

Practical user agent implementations have limits on the number and size of cookies that they can store. In general, user agents' cookie support should have no fixed limits. They should strive to store as many frequently-used cookies as possible. Furthermore, general-use user agents should provide each of the following minimum capabilities individually, although not necessarily simultaneously:

  • at least 300 cookies

  • at least 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header)

  • at least 20 cookies per unique host or domain name

If your session data is not valuable (as in "shouldn't be lost in case of e.g. a reboot"), consider storing it in memcached. This is pretty fast and avoids accessing the DB just to get session data. You might actually want to consider using a mix of both: You could create a small cookie containing the session id and login information. Then a loss of your server-side sessions would not result in users being logged out so the impact would be pretty low.

like image 101
ThiefMaster Avatar answered Sep 21 '22 08:09

ThiefMaster