Previous | Next --- Slide 40 of 58
Back to Lecture Thumbnails
oulgen

Why are we strictly keeping data cached per user? There could be many instances where a data could be shared across users. I guess finding the group of users that have that shared data might also be expensive.

Faust

I'm not positive, but I think this is an example in which the cost of getting a user object is very clear and simple. If the userid is in the cache, then we retrieve all of the data very quickly. If not, it is very expensive. If we did data sharing across users, the cost of user objects would be less clear because even if the userid is in the cache, it may still need to make some database queries to get some of the data.

parallelfifths

I imagine it depends a lot on the application. For some reason, the first that comes to mind is Amazon Prime account users making requests to stream videos. Caching data associated with my individual user account definitely makes sense. Amazon Prime Video remembers that I have TV series that I watch regularly, and I stereotypically watch maybe 2-3 episodes of a TV show in one sitting, so it may cache, for example objects associated with the home page of that TV show. But I also see @oulgen's point, because Amazon Prime typically offers only 1 or 2 movies for free streaming that are very recent box office hits, and it advertises these movies heavily. There's a good chance that a large portion of the user base will watch those 1 or 2 movies while online. This is an example where it make sense to cache data shared across users. (This example also reminds me of content distribution networks...)