What is the best state management to store user search criterias

493 Views Asked by At

What is the best state management to store user search criteria on different pages in ASP.NET MVC?

  • Session: stored on the server and may consume its RAM
  • Cookies: small size
  • local storage: it is javascript aside, but my codes are ready to cache data on controllers not the javascript side
  • cache: stored on the server and shared between different users, so if a user entered search criteria then other users will show its search results

notes:

  • the system may have thousand(s) of simultaneous users
  • I have 10 pages that I need to keep their search data
  • each page may contain up to 5 different search criteria (name, email, etc)
  • I don't need search data after the user logout
3

There are 3 best solutions below

0
On

you can use one of the below modes.

InProc - Sessions are stored inside of application's process on a web server. Depending on the IIS version used that could be aspnet_wp.exe or w3wp.exe.

StateServer - Sessions are stored using State Server windows service.

SQLServer - SQL Server database is used to store sessions' data

0
On

Every storage type has its own purpose.

  • [Pure ClientSide] sessionStorage: Data is expired when tab is closed.
  • [Pure ClientSide] localStorage: Data is never automatically expired.
  • [ClientSide + ServerSide] Cookies: Saving data is requested by server, Data is stored in client. Data has expiration time. - Data is submitted auto.
  • [ClientSide + ServerSide] Session: Saving data is request by server, data is stored in server, and special reference is saved in client side. Data expired when browser or site closed, server will terminate it after X time. - Data is submitted auto.

Search query parameters isn't an important data the server needs to be aware of, or even aware for every request.

I would rather save it as a Cookie or sessionStorage, with a big favor to sessionStorage due the nature of no server involvement is needed. and if you want multiple tabs to have that data, then a favor for localStorage.

0
On
  1. The system may have thousand(s) of simultaneous users

    In this case storing data on server will consume lot of memory for small chunks.

  2. I have 10 pages that i need to keep their search data each page may contain up to 5 different search criteria (name, email,etc)

    Sounds lot of information to store but not good to store them on either session or server database.

  3. I don't need search data after user logout

    You could clear/wipe out the data, once user clicks on logout.

Note:

  1. Storing data in session, consumes memory on your server, as your website traffic increases.

  2. Storing data in Database is not a good option, as you will have to make a request to server just to retrieve search criteria from database. your server will have to handle lot of requests.

I would recommend you to use IndexDb, which is a local storage database. You can store all of your user's specific search information on user's browser.

https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API