When I was working on my PokeLucky application (https://github.com/jeeheezy/sinatra-pokelucky), which interacts with the PokeApi, I tried to respect the PokeApi rule to cache information so there wouldn't be too many repetitive API calls. Since I was unfamiliar with how to cache information, I decided I'd just store the necessary data I got from the API into cookies to call back a later time. All was working fine until at a certain point, I got an error saying that I was trying to parse a nil object. Taking some time to debug, I found out it was because my conditions which look at if a Pokemon info was saved on a cookie did not take the expected "if" condition.
The core of the issue was that at a certain point, my cookie did not update with the latest information from the API because it had gotten too big. It seems that cookies have a byte limit of ~4000 bytes, which is not a lot. Even more to consider is that the best practice is to ensure the total bytesize of cookies doesn't exceed ~4000 per domain, not per cookie. I guess this is why learning how to use sessionStorage or localStorage is important since their storage capabilities are far greater than that of 4kb of cookies, although I'm not sure how one would access them in Ruby since I understand the two storages to be more front-end related.
TL;DR, cookies have bytesize limit and should not be the primary location to save continuous influx of data.
Top comments (0)