views:

52

answers:

1

Example:

[Authorize]
public ActionResult Index()
{
    var person = _userPersonalizationService.GetPersonForUser(User.Identity.Name);
    var campaigns = _campaignRepository.GetCampaignsByCompanyId(person.Company.CompanyId);
    return View(campaigns);
}

Basically every user is tied to a person model, and in this instance, I want the retrieve the campaigns of a user's associated company.

How would you wrap this retrieval mechanism so that I don't have to call the database every time and have a UserPersonalizationService in the controllers? Create a base UberController from which every controller is derived? Should I save the authorized user's Person data in the session container?

+1  A: 

I would store it in Cache.. then attach a cache dependency to the database, in the event those campaigns in the DB change, the dependency will break and the campaigns will be refreshed in cache.

datacop