Beispiel #1
0
        public async Task <GeoResponse> Query(string q)
        {
            var cacheKey = q.Replace(" ", "").ToLower();

            var result = await _memcachedClient.GetAsync <GeoResponse>(cacheKey);

            if (!result.Success)
            {
                var queryParts = _geoQueryParser.Parse(q);
                var sb         = new StringBuilder("https://api.geocod.io/v1/geocode?");

                foreach (var k in queryParts.Keys)
                {
                    sb.Append($"{k}={queryParts[k]}&");
                }

                sb.Append("api_key=");
                sb.Append(Environment.GetEnvironmentVariable("GEOCODIO_API_KEY"));

                var query = sb.ToString();

                var geo = await _geoQueryDispatchService.Query(query).ConfigureAwait(false);

                await _memcachedClient.StoreAsync(StoreMode.Add, cacheKey, geo, DateTime.Now.AddDays(7));

                return(geo);
            }
            else
            {
                return(result.Value);
            }
        }
Beispiel #2
0
        public async Task <GeoResponse> Query(string q)
        {
            var cacheKey = q.Replace(" ", "").ToLower();

            var queryParts = _geoQueryParser.Parse(q);
            var sb         = new StringBuilder("https://api.geocod.io/v1/geocode?");

            foreach (var k in queryParts.Keys)
            {
                sb.Append($"{k}={queryParts[k]}&");
            }

            sb.Append("api_key=");
            sb.Append(Environment.GetEnvironmentVariable("GEOCODIO_API_KEY"));

            var query = sb.ToString();

            var geo = await _geoQueryDispatchService.Query(query).ConfigureAwait(false);

            return(geo);
        }