public async Task <Response> Search(Search.Query query)
        {
            var cacheKey     = query.ToString();
            var redisAmadeus = await _cache.GetAsync(cacheKey);

            string serializedAmadeus = "";
            var    amadeusData       = new Response();

            if (redisAmadeus != null)
            {
                serializedAmadeus = Encoding.UTF8.GetString(redisAmadeus);
                amadeusData       = JsonConvert.DeserializeObject <Response>(serializedAmadeus);
            }
            else
            {
                amadeusData = await _amadeus.Search(query);

                serializedAmadeus = JsonConvert.SerializeObject(amadeusData);
                var encoded = Encoding.UTF8.GetBytes(serializedAmadeus);

                var options = new DistributedCacheEntryOptions()
                              .SetAbsoluteExpiration(DateTime.Now.AddMinutes(10))
                              .SetSlidingExpiration(TimeSpan.FromMinutes(2));

                await _cache.SetAsync(cacheKey, encoded, options);
            }

            return(amadeusData);
        }
Esempio n. 2
0
 public virtual void AddSpanQuery(Search.Query q)
 {
     if (q == SrndQuery.TheEmptyLcnQuery)
     {
         return;
     }
     if (!(q is SpanQuery))
     {
         throw new InvalidOperationException("Expected SpanQuery: " + q.ToString(FieldName));
     }
     AddSpanQueryWeighted((SpanQuery)q, q.Boost);
 }
Esempio n. 3
0
 public virtual void AddSpanQuery(Search.Query q)
 {
     if (q == SrndQuery.TheEmptyLcnQuery)
     {
         return;
     }
     if (!(q is SpanQuery))
     {
         throw AssertionError.Create("Expected SpanQuery: " + q.ToString(FieldName));
     }
     AddSpanQueryWeighted((SpanQuery)q, q.Boost);
 }