How to save data temporarily with good practices?

1

I have only one page where all the scripts are, when a user clicks on a certain data, it would redirect it to a specific script and I had to save this data (which he clicked) to be able to put in a case he wanted to edit this data later.

To do this, through JS I got the data, I sent it to the API in Java where I saved it as a session and then return it when necessary through a get method, in order to be able to put it as a value and it knows what data is being edited (No get, JS calls the API in which returns the data / session and JS inserts in the value).

I do not know if this was the best solution, are there others? A better practice? Without having to send the variable via the button via HTML.

    
asked by anonymous 24.02.2015 / 12:43

1 answer

3

In practice? No problem, if what you want is for an anonymous user or not to fill in a field in which after navigating any other page and returning to it, the field will always be filled in that session, the answer really is that.

Now a long answer: The big restriction that people usually (or at least in my experience) do in relation to saving data in SESSION is in relation to the size of the information you are storing, ie if this information is not so great no problem none at all. Now what would be great information? Well, in the case of the Session depends a lot on the capacity of your Server, my recommendation, nothing that exceeds the 100kb of storage, take as an example the Cookies that has a limit of 20 kb but that on the other hand are sent and received with each request, soon SESSION may be slightly larger.

The big question on when to choose the type of form of storage to adopt is to ask yourself questions like:

  • Is the information to store large?
  • Is the information temporary or should it be saved for a long time?
  • Is the information confidential?

With these questions I believe we can come to conclusions, for example:  - If it is not so large (100kb), temporary and confidential, I can save in session  - If it is small (2kb, 5kb), temporary and non-confidential, I can save in cookies  - If it is large I should save it to a bank or file (it would already be necessary to identify the user in some way).

Be clear that I am not imposing rules, keep in mind that rules are very important but nothing is better than common sense, every situation has its best alternative even if it breaks standards, as great writers have already said: rules have been made to be broken.

    
24.02.2015 / 13:09