Created
December 5, 2018 16:28
-
-
Save nest-don/bc82c6f12de0914b1586a6f4d5667549 to your computer and use it in GitHub Desktop.
This file contains 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
public byte[] GetRequest(byte[] data) | |
{ | |
SearchQuery query = _repo.GetQuery(Encoding.UTF8.GetString(data)); | |
List<SearchResult> cachedResults = null; | |
if (query != null && (DateTime.Now - query.Created).TotalSeconds < TTL) | |
{ | |
// If its a previous non-stale query then use the | |
// results stored in the cache | |
cachedResults = _repo. | |
ListResultsBySearchQuery(query.Id); | |
} | |
return Encoding.UTF8.GetBytes( | |
JsonConvert.SerializeObject(cachedResults)); | |
} |
This file contains 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
private List<SearchResult> GetCachedResults(string text) | |
{ | |
byte[] result = _cache.Call("GetRequest", Encoding.UTF8.GetBytes(text)); | |
return JsonConvert.DeserializeObject<List<SearchResult>>( | |
Encoding.UTF8.GetString(result)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment