Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Created November 11, 2013 11:08
Show Gist options
  • Select an option

  • Save danielmackay/7411605 to your computer and use it in GitHub Desktop.

Select an option

Save danielmackay/7411605 to your computer and use it in GitHub Desktop.
Example of a cached repository.
/// <summary>
/// Provides a cached repository of the DM lists
/// </summary>
internal class CachedRepository
{
private readonly ObjectCache cache = MemoryCache.Default;
private const string CacheName = "DM.Lists";
private const int ExpiryMinutes = 1;
public List<DMList> GetLists()
{
var data = cache[CacheName] as List<DMList>;
if (data != null)
return data;
try
{
var client = new DMListManagerSoapClient();
data = client.GetLists(AuthenticateManager.GodToken, 0, null).ToList();
}
catch (Exception ex)
{
throw new Exception("Failed to get lists or fields", ex);
}
var expiryDate = DateTime.Now.AddMinutes(ExpiryMinutes);
cache.Set(CacheName, data, expiryDate);
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment