예제 #1
0
        public async Task <PlacesApiQueryResponse> GetAsync <TItem>(ICacheKey <TItem> key, string keyword, double lat = 0, double lng = 0) where TItem : class
        {
            PlacesApiQueryResponse data;
            string cacheKey = $"{key.CacheKey}{keyword}";

            if (_memoryCache.TryGetValue(cacheKey, out data))
            {
                return(data);
            }
            else
            {
                if (lat > 0 && lng > 0)
                {
                    data = await _service.GetNearbyAsync(lat, lng); Add(data, cacheKey);
                }
                else
                {
                    data = await _service.GetGeoAsync(keyword); Add(data, cacheKey);
                }
            }
            return(data);
        }