Reputation: 7119
I have a system which allows users to schedule conference calls and invite people using their email address. This is implemented in ASP.net MVC 3, using EntityFramework in a Repository pattern. When a user is logged in I want to display a list of upcoming calls that they have either created or been invited to. The list should display details of the call and also the name / email address of the organiser, which are saved a the Username and a Profile field of the calls creator.
When the organiser is the logged on user this is fine however when the call was organised by another user I am retrieving the user by UserId (as this is stored against the call), and then retrieving their profile in order to display their name and a link to their email - if there are a large number of scheduled calls, or if I add a list of historical calls this could result in a significant number of database queries which doesn't feel optimal at all.
2 approaches I have considered are:
Is there another approach that I have not considered which could solve this in a optimised way?
Upvotes: 0
Views: 69
Reputation: 17480
You can cache the users' profiles (either in-memory [System.Web.Caching
/ System.Runtime.Caching
] or in some more sophisticated cache like Redis) and invalidate it when some user's profile changes.
Of course, you invalidate only the changed user's record, not the whole cache.
That way, you enjoy both worlds - hitting the memory instead of the database for the profile details, and still have up-to-date data if some of the users changes their profile.
Upvotes: 1