Cache VS Session VS cookies?

前端 未结 8 751
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 04:09

What are the do\'s and don\'ts about Cache VS Session VS Cookies?

For example:
I\'m using Session variables a lot and sometimes have problems in a booking-applic

相关标签:
8条回答
  • 2020-12-02 04:51

    Session is stored on the server will time out by default in 20 minutes (This is adjustable). I would store this in a cookie, or in viewstate(if available) to prevent the timeout.

    If your state is stored InProc(the default setup), then having more than one server in a farm is going to cause you issues also unless you have implemented some sort of "sticky session" that will keep the user on the same server in the farm for subsequent calls.

    I try to avoid session when possible(puts extra load and memory usage on the server), and keep viewstate turned off when possible to keep the page size low. Cookies are often the most lightweight option, but your users might have this turned off and you will need a fallback mode that still allows them to use the site.

    Edit (adding clarification based on response from asker):

    Viewstate is stored in a hidden field, and is a serialized representation of all objects in Viewstate storage. Viewstate is automatically used to store the page's state, but you can explicitly add and retrieve your own objects to and from Viewstate programatically if you choose to.

    So yes, datasets can be stored in Viewstate.

    0 讨论(0)
  • 2020-12-02 04:53

    Cookies are stored in browser as a text file format.It is stored limit amount of data.It is only allowing 4kb[4096bytes].It is not holding the multiple variable in cookies.

    we can accessing the cookies values in easily.So it is less secure.The setcookie() function must appear BEFORE the tag.

    Sessions are stored in server side.It is stored unlimit amount of data.It is holding the multiple variable in sessions. we cannot accessing the cookies values in easily.So it is more secure.

    0 讨论(0)
提交回复
热议问题