I have a system where I want to start introducing some 2nd level caching. I want to abstract data access a bit and allow some type of other class to do the dirty work of fetching a DTO; it will check cache first and only go to database if it has to. Also, it might do some additional work on the DTO before passing it back, like applying some business rules, etc. Would this be considered the Proxy, Facade, or "Manager" design pattern? Here is an example:
class UserDTO {
int Id {get;set;}
string UserName {get;set;}
}
class UserXXX { // <<< What is this called? Proxy, Facade, Manager?
UserDTO GetUser(int userId) {
UserDTO user;
//get user: check cache first
string cacheKey = "user_" + userId.ToString();
if (cache.Exists(cacheKey)){
user = cache.Get(cacheKey);
} else{
user = db.Users.Find(userId);
//add user to cache for next time
cache.Add(cacheKey, user);
}
//possibly do something else with user here,
//like authorization check or some other business logic
return user;
}
}