public void CacheResponse(OpenSearchRequest request, ref IOpenSearchResponse response)
{
CacheItem it = cache.GetCacheItem(request.OpenSearchUrl.ToString());
if (it != null) return;
if (response.Entity != null && !response.Entity.CanCache)
return;
var clonedResponse = response.CloneForCache();
if (clonedResponse == null)
throw new InvalidOperationException(string.Format("Response cannot be cached because it is null. Check the CloneForCache of the response [{0}] or the CanCache() method of the Opensearchable [{1}] requested", response.GetType(), response.Entity.GetType()));
OpenSearchResponseCacheItem item = new OpenSearchResponseCacheItem(request.OpenSearchUrl, clonedResponse);
CacheItemPolicy policy = this.CreatePolicy(item, request);
log.DebugFormat("OpenSearch Cache [store] {0}", request.OpenSearchUrl);
cache.Set(item, policy);
log.DebugFormat("OpenSearch Cache [count] {0}", cache.GetCount());
}