0

Can anyone please elaborate which is the faster way of fetching data. Fetching it from the database directly or fetching it from a List?

Suppose, in a java web application some data need to be operated on which are in databas, and they are also in a list and saved in a session or context. Now when the user sends a request it send some parameter as well, now on the basis of that parameter some data need to be fetched, which are in the list or in the database. As the application is a multi user application there will be lots of request coming towards the server, so interacting with database for each request is not seem like a good option, and fetching it from the list seems like a slow way.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Pranjut
  • 1,747
  • 5
  • 18
  • 31

1 Answers1

0

I'm pretty sure that this relies heavily on the length of your current stored list, as well as the size of the database. It's really hard to answer a question like this without a more specific example.

Benjamin Kovach
  • 3,190
  • 1
  • 24
  • 38
  • Well if the stored data are long enough, and while fetching it, it needs more parameters rather than only the id, then what would be the option? – Pranjut Jul 05 '12 at 19:42
  • It's all variable -- the speed of a search is something you'd either have to test extensively or analyze specifically. I can't give a straight answer to that question because I'm not sure how efficient the search algorithms are for your specific database or the list implementation you're using. Algorithmic time complexity (http://en.wikipedia.org/wiki/Time_complexity) isn't quite that simple, unfortunately. – Benjamin Kovach Jul 05 '12 at 19:49
  • Thank for showing interest in my question. If the fetching form the database is faster than the fetching from the list one, at that point would it be good to hit database that much? – Pranjut Jul 05 '12 at 20:14
  • Sure, why not? If you can see that it's happening faster that way, you should do it that way. But, that leaves me wondering what the list is even for, if you're not going to be fetching elements from it? – Benjamin Kovach Jul 05 '12 at 20:16
  • The list is an alternate for the interacting with the database too much, because all over the database topics, it says that we must not interact with database too much. – Pranjut Jul 06 '12 at 07:52