Skip to content

Instantly share code, notes, and snippets.

@nest-don
Created December 5, 2018 16:28
Show Gist options
  • Save nest-don/bc82c6f12de0914b1586a6f4d5667549 to your computer and use it in GitHub Desktop.
Save nest-don/bc82c6f12de0914b1586a6f4d5667549 to your computer and use it in GitHub Desktop.
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));
}
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