Phân biệt cookie, cache và session

Phân biệt cookie, cache và session?

Written by IT Phú Trần on 11/04/2017 in Câu hỏi phỏng vấn and KINH NGHIỆM LẬP TRÌNH and LẬP TRÌNH JAVA and LẬP TRÌNH PHP with 136 comments.

Phân biệt cookie, cache và session? Đây thật sự là một câu hỏi luôn được đặt ra khi các bạn đi phỏng vấn ở các công ty.Nếu bạn còn đang băn khoăn thì đây là bài viết giúp bạn giải quyết vấn đề trên.Trước khi tôi đi vào giải quyết câu hỏi phân biệt giữa cookie, cache và session thì đầu tiên chúng ta sẽ điểm qua về định nghĩa.

Cookie là gì?

Cookie là một phần nhỏ thông tin được lưu trữ trên máy tính của bạn bởi một trang web bạn truy cập. Mỗi khi người dùng tải trang web, trình duyệt sẽ gửi cookie trở lại máy chủ để thông báo cho trang web về hoạt động trước đó của người dùng. Cookie có một khoảng thời gian nhất định do những người sáng tạo của họ xác định. Cookie thường theo dõi thông tin như tần suất người dùng ghé thăm, thời gian truy cập, những gì đã được nhấp vào biểu ngữ, nhấp vào nút nào, sở thích của người dùng, các mục trong giỏ hàng, v.v. Điều này cho phép trang web hiển thị cho bạn thông tin tùy chỉnh Phù hợp với nhu cầu của bạn. Cookie thường được sử dụng để lưu trữ thông tin cần thiết cho thời kỳ ngắn hơn.

Cache là gì?

Bộ nhớ cache web (hoặc bộ nhớ cache HTTP) là một công nghệ thông tin để lưu trữ tạm thời (lưu trữ) các tài liệu web, chẳng hạn như các trang và hình ảnh HTML, để giảm tải băng thông, tải máy chủ và tụt hậu. Một hệ thống lưu trữ web lưu trữ bản sao các tài liệu đi qua nó; Các yêu cầu tiếp theo có thể được thỏa mãn từ bộ nhớ cache nếu đáp ứng các điều kiện nhất định. Hệ thống bộ nhớ cache web có thể tham chiếu đến thiết bị hoặc phần mềm. Ví dụ: khi bạn mở các trang web có hình ảnh và video lớn, có thể mất một thời gian để tải trang web. Trình duyệt web lưu trữ nội dung trang web như hình ảnh, video, âm thanh, vv trên máy tính của bạn. Vì vậy, lần tiếp theo bạn tải cùng một trang web, bạn sẽ thấy nó tải nhanh hơn.

Session là gì?

Session được lưu trữ ở phía máy chủ không phải trong máy của người dùng. Một phiên có sẵn miễn là mở trình duyệt. Người dùng không thể bị vô hiệu hóa phiên. Chúng ta có thể lưu trữ không chỉ chuỗi mà còn các đối tượng trong phiên.

Vấn đề chính của phiên làm việc là ngay khi đóng trình duyệt thì sẽ mất phiên làm việc và tất cả các thông tin đều bị mất.

 

Phân biệt cookie, cache và session

Bây giờ chúng ta hãy so sánh,phân biệt giữa Cache và Cookies

Mặc dù cookie và bộ nhớ cache là hai cách để lưu trữ dữ liệu trên máy của khách hàng, nhưng có sự khác biệt giữa bộ nhớ cache và cookie và chúng phục vụ các mục đích khác nhau.
Cookie được sử dụng để lưu trữ thông tin để theo dõi các đặc điểm khác nhau liên quan đến người dùng, trong khi bộ nhớ cache được sử dụng để làm cho việc tải các trang web nhanh hơn.
Các cookie lưu trữ thông tin như sở thích của người dùng, trong khi bộ nhớ cache sẽ giữ các tập tin tài nguyên như tệp âm thanh, video hoặc flash.
Thông thường, cookie hết hạn sau một thời gian, nhưng bộ nhớ cache được giữ trong máy của khách hàng cho đến khi người dùng gỡ bỏ nó bằng tay.

 

phan biet-cache-and-cookies.jpg

Sự khác biệt chính giữa Cookie và Session:

Cookie Session
Cookie được lưu trữ trên trình duyệt của người dùng. Số phiên không được lưu trữ trong trình duyệt của người dùng.
Dữ liệu cookie được lưu trữ ở phía máy khách. Dữ liệu session được lưu trữ ở phía máy chủ.
Dữ liệu cookie dễ dàng sửa đổi khi chúng được lưu trữ ở phía khách hàng. Dữ liệu phiên không dễ dàng sửa đổi vì chúng được lưu trữ ở phía máy chủ.
Dữ liệu cookie có sẵn trong trình duyệt của chúng ta đến khi hết hạn. Dữ liệu phiên có sẵn cho trình duyệt chạy. Sau khi đóng trình duyệt sẽ mất thông tin phiên.

 

Ví dụ về bộ nhớ cache,cookie và session

Một ví dụ nhỏ để phân biệt sự khác biệt giữa bộ nhớ cache và cookie,session. Giả sử bạn truy cập trang web mua sắm để tìm kiếm hoặc mua một đôi giày. Bạn kiểm tra một số đôi giày của thương hiệu khác nhau hoặc mua đôi các sản phẩm vào giỏ hàng. Sau đó, bạn mua hoặc rời khỏi trang web mà không thanh toán. Và bây giờ bạn duyệt qua bất kỳ trang web nào khác, cho dù đó là trang web tin tức hay bất kỳ trang nào khác có phục vụ quảng cáo. Bạn sẽ nhận thấy rằng tất cả các sản phẩm bạn đã tìm kiếm hoặc mua thì các quảng cáo liên quan đến các sản phẩm đó bạn sẽ thấy. Đôi khi nó có thể là sản phẩm khác nhau từ một trang web khác nhau hoặc cùng một sản phẩm từ cùng một trang web. Điều này được thực hiện nhờ sự giúp đỡ của cookie.

Bây giờ chúng ta hãy kiểm tra vai trò của các cookie trong đó. Cookie để lưu trữ thông tin về lịch sử duyệt web của bạn. Trong trường hợp này, nó sẽ lưu trữ trang web bạn đã duyệt và loại sản phẩm bạn tìm kiếm. Thông tin đó hiện giúp các nhà quảng cáo hiển thị cho bạn cùng một sản phẩm hoặc sản phẩm có liên quan trong quảng cáo của họ.

Vai trò của bộ nhớ cache trong ví dụ này là để lưu trữ hình ảnh của các sản phẩm mà bạn đã duyệt và các nguồn web khác. Bây giờ, khi bạn truy cập lại trang web đó hoặc sản phẩm trang hoặc hình ảnh sẽ tải nhanh hơn.

Với Session thì nó thường dùng để thực hiện các chức năng như đăng nhập,lưu thông tin của giỏ hàng mua sắm trên các trang web.


Đó là tất cả về sự khác biệt giữa bộ nhớ cache, cookie và session. Hãy để lại câu hỏi của bạn  nếu có trong nhận xét. Nếu bạn thích bài viết này, xin vui lòng chia sẻ nó.

136 Responses to “Phân biệt cookie, cache và session?

  1. Cảm ơn ad nhưng ad cho mình hỏi là khi nào thì session tự động bị hủy. Mình đọc thì trên một vài trang khác thì session bị hủy khi người dùng thoát khỏi trình duyệt, nhưng một số comment khác thì cho rằng session bị hủy khi đến thời gian timeout. Rất mong ad giải đáp.

  2. cả 2 trường hợp trên đều sẽ bị hủy, hoặc do lệnh hủy vd đăng xuất

  3. Howdy! This is kind of off topic but I need some advice from an established
    blog. Is it tough to set up your own blog? I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about making my own but I’m not sure where to begin. Do you
    have any ideas or suggestions? Many thanks

  4. Hi, I do think this is an excellent blog. I stumbledupon it
    😉 I will revisit yet again since i have
    saved as a favorite it. Money and freedom is the greatest
    way to change, may you be rich and continue to help others.

  5. I’m not sure where you are getting your information, but good topic.
    I needs to spend some time learning more or understanding
    more. Thanks for magnificent info I was looking for this information for my mission.

  6. I’m extremely impressed with your writing skills as well as with the layout on your
    blog. Is this a paid theme or did you modify it yourself?

    Either way keep up the excellent quality writing, it is rare to see a nice blog like this one today.

  7. Wonderful site you have here but I was wanting to know if you knew of
    any message boards that cover the same topics talked about here?
    I’d really love to be a part of group where I can get opinions from other knowledgeable individuals
    that share the same interest. If you have any recommendations, please let me know.
    Bless you!

  8. I’m extremely pleased to uncover this great site. I want to to thank you for ones
    time for this fantastic read!! I definitely appreciated every part of it and I have you book-marked to look at new information on your website.

  9. I really like what you guys are usually up too.
    This type of clever work and exposure! Keep up the awesome works guys I’ve incorporated you guys to our blogroll.

  10. You actually make it seem so easy with your presentation but I find this topic to be really
    something which I think I would never understand. It seems too complex and very
    broad for me. I am looking forward for your next post, I’ll
    try to get the hang of it!

  11. I just want to mention I am just beginner to weblog and definitely liked you’re page. Likely I’m going to bookmark your website . You actually have beneficial posts. Bless you for sharing your web site.

  12. One other issue issue is that video games usually are serious naturally with the principal focus on understanding rather than entertainment. Although, there’s an entertainment factor to keep your children engaged, every game will likely be designed to work with a specific expertise or course, such as math or scientific discipline. Thanks for your post.

  13. I was recommended this website by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. You’re wonderful! Thanks!

  14. Nice post. I learn something totally new and challenging on blogs I stumbleupon everyday. It will always be exciting to read through articles from other writers and practice something from other web sites.

  15. Next time I read a blog, I hope that it does not disappoint me as much as this one. I mean, I know it was my choice to read, but I genuinely believed you’d have something helpful to say. All I hear is a bunch of moaning about something that you could possibly fix if you were not too busy seeking attention.

  16. After looking into a handful of the articles on your web page, I honestly appreciate your way of writing a blog. I saved it to my bookmark webpage list and will be checking back soon. Please check out my web site too and tell me how you feel.

  17. I’m impressed, I have to admit. Rarely do I come across a blog that’s both educative and interesting, and without a doubt, you’ve hit the nail on the head. The problem is an issue that too few folks are speaking intelligently about. I’m very happy I stumbled across this during my search for something regarding this.

  18. Hi there! I could have sworn I’ve been to this site before but after going through some of the articles I realized it’s new to me. Nonetheless, I’m certainly pleased I discovered it and I’ll be book-marking it and checking back often!

  19. I have observed that in the world nowadays, video games will be the latest popularity with kids of all ages. Occasionally it may be extremely hard to drag your kids away from the video games. If you want the very best of both worlds, there are many educational video games for kids. Interesting post.

  20. Your style is so unique in comparison to other people I’ve read stuff from. Thanks for posting when you’ve got the opportunity, Guess I’ll just book mark this page.

  21. Howdy! I could have sworn I’ve visited this site before but after looking at a few of the articles I realized it’s new to me. Nonetheless, I’m certainly pleased I found it and I’ll be book-marking it and checking back often.

  22. Howdy, I do believe your blog could possibly be having internet browser compatibility problems. When I take a look at your web site in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping issues. I simply wanted to provide you with a quick heads up! Apart from that, great blog.

  23. Having read this I thought it was very enlightening. I appreciate you taking the time and energy to put this informative article together. I once again find myself spending way too much time both reading and commenting. But so what, it was still worth it!

  24. After looking at a handful of the blog posts on your web page, I honestly like your technique of writing a blog. I saved it to my bookmark website list and will be checking back in the near future. Take a look at my web site as well and tell me what you think.

  25. I would like to thank you for the efforts you have put in penning this website. I really hope to check out the same high-grade content by you later on as well. In fact, your creative writing abilities has inspired me to get my very own site now 😉

  26. Hi there! This blog post couldn’t be written much better! Looking through this article reminds me of my previous roommate! He constantly kept talking about this. I most certainly will send this information to him. Pretty sure he’s going to have a good read. Thanks for sharing!

  27. Sapid Agency is a Search Engine Optimization company in New York City that provides SEO Services. Their proprietary SEO strategies help struggling websites and aspiring business owners to rank their websites higher in multiple search engines like Google , Yahoo and Bing. They provide local and gmb map ranking for businesses in NYC and many other local areas. Find more at https://www.sapidagency.com/ @ 145 E 57TH NEW YORK, NY 10022, USA, +1 971 341 5608 USA

  28. When I initially commented I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I recieve four emails with the same comment. Perhaps there is a means you can remove me from that service? Thank you.

  29. Howdy, I do believe your site could possibly be having internet browser compatibility issues. When I take a look at your website in Safari, it looks fine however, when opening in I.E., it’s got some overlapping issues. I simply wanted to provide you with a quick heads up! Other than that, wonderful website.

  30. It’s actually almost close to impossible to find well-advised people on this area, nevertheless you come across as like you fully understand those things you’re talking about! Many Thanks

  31. Howdy, I believe your web site could be having web browser compatibility issues. When I take a look at your website in Safari, it looks fine however, if opening in I.E., it’s got some overlapping issues. I just wanted to give you a quick heads up! Other than that, great website!

  32. Hi, I do believe your website could be having browser compatibility issues. Whenever I look at your website in Safari, it looks fine however, when opening in I.E., it’s got some overlapping issues. I just wanted to provide you with a quick heads up! Other than that, fantastic site.

  33. Excellent web site you’ve got here.. It’s hard to find excellent writing like yours nowadays. I seriously appreciate individuals like you! Take care!!

  34. MetroClick specializes in building completely interactive products like Photo Booth for rental or sale, Touch Screen Kiosks, Large Touch Screen Displays , Monitors, Digital Signages and experiences. With our own hardware production facility and in-house software development teams, we are able to achieve the highest level of customization and versatility for Photo Booths, Touch Screen Kiosks, Touch Screen Monitors and Digital Signage. Visit MetroClick in NYC at http://www.metroclick.com/ or , 121 Varick St, New York, NY 10013, +1 646-843-0888.

  35. Nice post. I learn something totally new and challenging on sites I stumbleupon on a daily basis. It will always be exciting to read through articles from other writers and practice something from their web sites.

  36. Hi, I do think this is a great site. I stumbledupon it 😉 I’m going to return yet again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to guide other people.

  37. Hi there, I believe your web site could possibly be having internet browser compatibility issues. When I take a look at your website in Safari, it looks fine however, if opening in IE, it has some overlapping issues. I merely wanted to give you a quick heads up! Besides that, fantastic blog.

  38. I merely intend to share it with you that I am new to posting and very much cherished your page. Most likely I am inclined to bookmark your blog post . You certainly have extraordinary article materials. Love it for expressing with us your favorite internet webpage

  39. Howdy! I just want to give you a big thumbs up for your great information you’ve got right here on this post. I am coming back to your website for more soon.

  40. Hello there! I simply would like to offer you a big thumbs up for the excellent info you have got right here on this post. I’ll be coming back to your web site for more soon.

  41. Excellent blog you have here.. It’s difficult to find high quality writing like yours these days. I really appreciate people like you! Take care!!

  42. I wanted to thank you for this very good read!! I certainly loved every little bit of it. I’ve got you book marked to check out new things you post…

  43. Having read this I believed it was really informative. I appreciate you finding the time and energy to put this informative article together. I once again find myself spending a significant amount of time both reading and posting comments. But so what, it was still worthwhile.

  44. An impressive share! I have just forwarded this onto a friend who was conducting a little homework on this. And he in fact ordered me dinner simply because I discovered it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanks for spending some time to discuss this subject here on your web page.

  45. Hello there! I could have sworn I’ve been to this web site before but after looking at a few of the articles I realized it’s new to me. Nonetheless, I’m certainly delighted I discovered it and I’ll be book-marking it and checking back frequently!

  46. I’m amazed, I must say. Seldom do I encounter a blog that’s equally educative and engaging, and let me tell you, you have hit the nail on the head. The issue is an issue that too few folks are speaking intelligently about. Now i’m very happy that I came across this during my hunt for something regarding this.

  47. Right here is the perfect site for anyone who really wants to understand this topic. You realize so much its almost tough to argue with you (not that I really will need to…HaHa). You certainly put a new spin on a topic that has been discussed for ages. Excellent stuff, just wonderful.

  48. Howdy! I just wish to offer you a huge thumbs up for your great information you have got right here on this post. I am coming back to your blog for more soon.

  49. Way cool! Some very valid points! I appreciate you writing this article and also the rest of the website is really good.

  50. Hello, Neat post. There is a problem together with your site in web explorer, could check this… IE still is the market chief and a large element of other folks will pass over your excellent writing because of this problem.

  51. I would like to thank you for the efforts you’ve put in penning this website. I’m hoping to view the same high-grade content by you in the future as well. In truth, your creative writing abilities has encouraged me to get my own blog now 😉

  52. You need to take part in a contest for one of the highest quality websites on the web. I am going to highly recommend this website!

  53. I’m impressed, I have to admit. Rarely do I encounter a blog that’s both educative and interesting, and without a doubt, you’ve hit the nail on the head. The issue is an issue that too few people are speaking intelligently about. I am very happy I found this in my hunt for something regarding this.

  54. I seriously love your blog.. Great colors & theme. Did you develop this site yourself? Please reply back as I’m looking to create my own blog and would like to find out where you got this from or just what the theme is named. Thank you.

  55. I’m amazed, I must say. Seldom do I encounter a blog that’s both equally educative and interesting, and without a doubt, you’ve hit the nail on the head. The issue is an issue that not enough people are speaking intelligently about. Now i’m very happy that I found this in my search for something relating to this.

  56. An impressive share! I have just forwarded this onto a colleague who has been doing a little homework on this. And he actually bought me lunch simply because I found it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanx for spending time to talk about this topic here on your web page.

  57. An intriguing discussion is worth comment. I do believe that you should write more about this topic, it might not be a taboo subject but generally folks don’t talk about such issues. To the next! Kind regards.

  58. Next time I read a blog, Hopefully it doesn’t fail me just as much as this one. After all, I know it was my choice to read through, but I really thought you’d have something helpful to say. All I hear is a bunch of complaining about something you could fix if you weren’t too busy seeking attention.

  59. The very next time I read a blog, Hopefully it doesn’t fail me as much as this particular one. After all, I know it was my choice to read, nonetheless I actually thought you would have something interesting to say. All I hear is a bunch of crying about something you could fix if you weren’t too busy looking for attention.

  60. Your style is so unique compared to other people I have read stuff from. Thanks for posting when you have the opportunity, Guess I will just book mark this site.

  61. Nice post. I learn something new and challenging on sites I stumbleupon on a daily basis. It’s always exciting to read through articles from other writers and practice a little something from other web sites.

  62. An interesting discussion is worth comment. I think that you ought to publish more about this subject, it might not be a taboo matter but typically folks don’t speak about such topics. To the next! Cheers!

  63. Oh my goodness! Amazing article dude! Thank you, However I am encountering problems with your RSS. I don’t understand the reason why I am unable to subscribe to it. Is there anybody else getting identical RSS problems? Anyone that knows the answer will you kindly respond? Thanks!!

  64. After looking into a handful of the articles on your web page, I really like your way of writing a blog. I book-marked it to my bookmark webpage list and will be checking back in the near future. Please check out my website as well and tell me what you think.

  65. Google

    Wonderful story, reckoned we could combine a couple of unrelated data, nevertheless truly worth taking a search, whoa did one study about Mid East has got much more problerms also.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *