eBay Inc.

  www.ebay.com
Work in HR? Unlock Free Profile

eBay Inc. Software Engineering Interview Question (student candidate)

I interviewed in Pudong, Shanghai (China) and was asked:
"What is the difference of session, cookie and cache?"
Add Tags [?]
Answer

Part of a Software Engineering Interview Review - one of 326 eBay Inc. Interview Reviews

Answers & Comments

0
of 0
votes
The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. This difference determines what each is best used for.
A cookie can keep information in the user's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie. The trouble is that a user can block cookies or delete them at any time. If, for example, your website's shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.

Sessions are not reliant on the user allowing a cookie. They work instead like a token allowing access and passing information while the user has their browser open. The problem with sessions is that when you close your browser you also lose the session. So, if you had a site requiring a login, this couldn't be saved as a session like it could as a cookie, and the user would be forced to re-login every time they visit.

On the other hand cache is a repository of saved data, but the cache stores any files needed to view a website (text, images, other media) so that the page load time is shorter if you happen to visit the page again in the future. For example, if I have a 1 MB image on my home page, it would be a hassle to load the image from the Internet again and again -- instead, the local copy of the image in the cache is loaded into the browser, making the overall load time a lot faster.
- yash on Feb 29, 2012
0
of 0
votes
@yash : your answer is not correct. Cookies can be in browsers and in file system as files, both ! Simply put Cookies are used to implement sessions because http is stateless. They should not be compared.
- Manish on Mar 18, 2012

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.