Skip to content

Instantly share code, notes, and snippets.

@mverzilli
Created March 27, 2012 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mverzilli/2217535 to your computer and use it in GitHub Desktop.
Save mverzilli/2217535 to your computer and use it in GitHub Desktop.
Storified service method
public User GetUserByEmail(string email)
{
/*
* I use the email param as a key to get a user from cache,
* so I store the email in a variable called "key".
* If the user is in cache, we're done! If the user isn't in cache,
* I try to get it from the new database.
* If the user isn't in the new database, everything may blow up,
* so I have to be careful just in case it does.
* There's no way for me to know whether the user
* is actually there before blowing everything up.
* Now, supposing it does blow up, I try to get the user from the old database.
* I still need to be careful because if the user isn't there
* everything may blow up as well (it seems this is a very delicate system).
* If it does blow up again, the user doesn't exist,
* which means I shouldn't have been called.
* I'll express my anger by throwing an exception to the caller.
* If we're lucky enough, the user was either at the new or the old database.
* We cache it, so that we don't need to get through all of this next time it's needed.
* That's it, here's your user, now let me have some rest.
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment