Windows Azure Caching: Difference between revisions

Content deleted Content added
Rothja (talk | contribs)
Rothja (talk | contribs)
Code examples: Modified the code samples to correct errors and make them easier to read and understand
Line 56:
 
<syntaxhighlight lang=CSharp>
dataType get_user_dataGetUserData(string userid)
{
/*/ firstAttempt tryto retrieve the cacheuser */data from the cache:
dataType data = (dataType)cacheCache.Get(userid) ;
 
if (!data == null) {
/* not found : request database */
// If it doesn't exist in the cache, retrieve it from the database:
data = db_selectGetUserDataFromDatabase("SELECT * FROM users WHERE userid = ?@userid", userid);
/* then store in cache until next get */
 
// Put the returned data in the cache for future requests:
Cache.Add(userid, data);
}
 
return data;
}
Line 72 ⟶ 76:
 
<syntaxhighlight lang=CSharp>
void update_user_dataUpdateUserData(string userid, stringdataType dbUpdateStringdata) {
{
/* first update database */
// Update the user information in the database:
result = db_execute(dbUpdateString);
result = UpdateUserDataInDatabase(data);
if (result) {
/* database update successful : fetch data to be stored in cache */
if (result) {
data = db_select("SELECT * FROM users WHERE userid = ?", userid);
{
/* then store in cache to support future get calls */
// If successfully updated, update the cache:
Cache.Put(userid, data);
}