Guest User

Untitled

a guest
Jan 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. internal static User GetUserByID(int userID)
  2. {
  3. string Key = "User-" + userID;
  4.  
  5. if (HttpContext.Current.Cache[Key] == null)
  6. {
  7. // cache is empty - populate from DB
  8. var user = new User(UserManager.GetUserInfoByID(userID));
  9.  
  10. // store in cache
  11. HttpContext.Current.Cache.Insert(Key, user, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration);
  12. }
  13.  
  14. // return data from cache
  15. return HttpContext.Current.Cache[Key] as User;
  16. }
Add Comment
Please, Sign In to add comment