Skip to content

Instantly share code, notes, and snippets.

@jonocairns
jonocairns / redis-try-get-set
Last active August 29, 2015 14:15
Cache wrapper for redis which will try get a value from the cache - if it doesn't exist it will perform the method you supply and set that as the cache value
//cache
public async Task<T> TryGet<T>(string key, Func<Task<T>> ifCacheMissAction)
{
if (ifCacheMissAction == null) throw new ArgumentNullException("ifCacheMissAction");
if (string.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
if (_isEnabled)
{
RedisValue redisValue = Cache.StringGet(key);
// the following is a bit yolo
if (redisValue.HasValue && redisValue != "{}")
@jonocairns
jonocairns / c#-integration-client-rest-sharp
Last active August 29, 2015 14:15
Example integration client
public class IntegrationClient : IIntegrationClient
{
private readonly ISettings _settings;
public IntegrationClient(ISettings settings)
{
if (settings == null) throw new ArgumentNullException("settings");
_settings = settings;
}
public async Task<T> ExecuteGetRequest<T>(RestRequest request)
{