Is it faster to recreate an object or store it in a session variable?

Sorry if this seems obvious to non-noob. Is it faster:

  • Recreate the instance of the object each time someone goes to the page during a session

or

  • Store the instance of the object in a session variable when it is first created, and then always retrieve it from there when the page opens again.

I'm not sure it will be "How long is this piece of string?" the question is, but if so, then maybe you could tell me what factors are involved in the decision?

+3
source share
5 answers

, , - , , - . , , , , , . , , , .

+4

, , . .

0

, , . .., .

0

, , , , . , , .

0

, . , , .

, , , . , .

This is good, but it makes it harder to check concurrency - let's say your object has a timestamp of the last saved time - if you reload it every time before saving, you can easily check if the timestamp has changed since the last load, in which case you may need to stop saving from continuing.

In any case, the difference will not be huge.

0
source

Source: https://habr.com/ru/post/1774269/


All Articles