Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

storing a 3kb json in cookies, as a file on server or in the database


I have a json file that I need to store for each user.

  1. Storing as a cookie
    The json is 3kb so it's less than the 4kb limit the cookies have

  2. Storing as a file on
    my server /json/user13.json

  3. Storing in the database
    (user_id (int, primary key), json (blob)

This will be retrieved quite often
The json file will be initially generated from the database and
I'm thinking of storing it as a cookie or file as a way to help
the server perform slightly faster.

Thank you!

like image 495
inrob Avatar asked Jul 01 '15 11:07

inrob


Video Answer


1 Answers

Will not let me put a simple comment so I extend a bit for fun, have you thought about using html5 localStorage?

Write:

var obj = {foo: 'bar'};
localStorage.setItem('obj', JSON.stringify(obj)); //<-- saved as JSON string

(saved as string because you can not save json objects in localStorage, soo, strings, and you has a 5 mb limit i think)

Read later:

var obj = JSON.parse(localStorage.getItem('obj'));

I do not know if it's an option for you in this case

Edit:

For other browsers without localStorage can use https://github.com/wojodesign/local-storage-js

Basically when not have localStorage use or Global Storage: - https://developer.mozilla.org/en/dom/storage#globalStorage

Or userData: - http://msdn.microsoft.com/en-us/library/ms531424(v=vs.85).aspx

I do not know how much support 'back' is achieved, but allows browsers such as IE5, 6 and 7

like image 61
Worvast Avatar answered Sep 18 '22 21:09

Worvast