Created
November 11, 2013 11:08
-
-
Save danielmackay/7411605 to your computer and use it in GitHub Desktop.
Example of a cached repository.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <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