Skip to content

Commit

Permalink
added server cache lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
markentingh committed May 25, 2017
1 parent 3cba906 commit 9397d6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion App/CSS/tapestry
14 changes: 14 additions & 0 deletions App/Core/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ public void SaveToCache(string key, string value)
Cache.Add(key, value);
}
}

public T GetFromCache<T>(string key, Func<T> value, bool serialize = true)
{
if(Cache[key] == null)
{
var obj = value();
SaveToCache(key, serialize ? S.Util.Serializer.WriteObjectAsString(obj) : obj);
return obj;
}
else
{
return serialize ? (T)S.Util.Serializer.ReadObject((string)Cache[key], typeof(T)) : (T)Cache[key];
}
}
#endregion
}
}

0 comments on commit 9397d6e

Please sign in to comment.