简体   繁体   English

将3kb json存储在cookie中,作为服务器或数据库中的文件

[英]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. 我有一个json文件,我需要为每个用户存储。

  1. Storing as a cookie 存储为cookie
    The json is 3kb so it's less than the 4kb limit the cookies have json是3kb,因此它低于cookie的4kb限制

  2. Storing as a file on 存储为文件
    my server /json/user13.json 我的服务器/json/user13.json

  3. Storing in the database 存储在数据库中
    (user_id (int, primary key), json (blob) (user_id(int,primary key),json(blob)

This will be retrieved quite often 这将经常被检索
The json file will be initially generated from the database and json文件最初将从数据库生成
I'm thinking of storing it as a cookie or file as a way to help 我正在考虑将其存储为cookie或文件作为一种帮助方式
the server perform slightly faster. 服务器执行速度稍快。

Thank you! 谢谢!

Will not let me put a simple comment so I extend a bit for fun, have you thought about using html5 localStorage? 不会让我发表一个简单的评论,所以我延长了一点乐趣,你有没有想过使用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) (保存为字符串,因为你无法在localStorage,soo,字符串中保存json对象,我认为你有5 MB的限制)

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 对于没有localStorage的其他浏览器,可以使用https://github.com/wojodesign/local-storage-js

Basically when not have localStorage use or Global Storage: - https://developer.mozilla.org/en/dom/storage#globalStorage 基本上没有localStorage使用或全局存储时: - https://developer.mozilla.org/en/dom/storage#globalStorage

Or userData: - http://msdn.microsoft.com/en-us/library/ms531424(v=vs.85).aspx 或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 我不知道有多少支持“后退”,但允许浏览器,如IE5,6和7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM