returns API reponse from cache or raises ValueError
359242
def _load_response(self, action):
        
        _query = self.cache[action]['query'].replace('&format=json', '')
        response = self.cache[action]['response']

        if not response:
            raise ValueError("Empty response: %s" % self.params)

        try:
            data = utils.json_loads(response)
        except ValueError:
            raise ValueError(_query)

        if data.get('warnings'):
            if 'WARNINGS' in self.data:
                self.data['WARNINGS'].update(data['warnings'])
            else:
                self.data['WARNINGS'] = data['warnings']

        if data.get('error'):
            utils.stderr("API error: %s" % data.get('error'))
            raise LookupError(_query)

        if 'query' in action and data.get('query'):
            if data['query'].get('pages'):
                if data['query']['pages'][0].get('missing'):
                    raise LookupError(_query)

        if action == 'parse' and not data.get('parse'):
            raise LookupError(_query)

        if action == 'wikidata':
            handle_wikidata_errors(data, _query)

        return data
770322
def bulk_lookup(self, api_name, keys):
        
        cached_data = {}

        for key in keys:
            value = self.lookup_value(api_name, key)
            if value is not None:
                cached_data[key] = value
        return cached_data
736447
function checkCacheResponse(key, err, result, type, cacheIndex){
    if(err){
      log(true, 'Error when getting key ' + key + ' from cache of type ' + type + ':', err);

      if(cacheIndex < self.caches.length - 1){
        return {status:'continue'};
      }
    }
    //THIS ALLOWS false AS A VALID CACHE VALUE, BUT DO I WANT null TO BE VALID AS WELL?
    if(result !== null && typeof result !== 'undefined'){
      log(false, 'Key found:', {key: key, value: result});
      return {status: 'break', result: result};
    }
    var curCache = self.caches[cacheIndex];
    for(var i = cacheIndex + 1; i < self.cachesLength; i++) {
      var nextCache = self.caches[i];
      if(nextCache.checkOnPreviousEmpty || nextCache.expiration > curCache.expiration){
        return {status:'continue', toIndex: i};
      }
    }
    return {status: 'else'};
  }
757967
def execute(self, ignore_cache=False):
        
        if ignore_cache or not hasattr(self, '_response'):
            es = connections.get_connection(self._using)

            self._response = self._response_class(
                self,
                es.search(
                    index=self._index,
                    body=self.to_dict(),
                    **self._params
                )
            )
        return self._response
547671
def fetch_cache_key(request):
        
        m = hashlib.md5()
        m.update(request.body)

        return m.hexdigest()
881955
def get(self, object_type, cache_key):
        
        if object_type not in self.mapping or self.disabled:
            return None
        cache = self.mapping[object_type]
        if cache_key in cache:
            log.debug("Cache HIT: [%s %s]" % (object_type.capitalize(), cache_key))
            return cache[cache_key]
        else:
            log.debug('Cache MISS: [%s %s]' % (object_type.capitalize(), cache_key))
516815
def get_cached_response(cls, key):
        
        request_cached_response = DEFAULT_REQUEST_CACHE.get_cached_response(key)
        if not request_cached_response.is_found:
            django_cached_response = cls._get_cached_response_from_django_cache(key)
            cls._set_request_cache_if_django_cache_hit(key, django_cached_response)
            return django_cached_response

        return request_cached_response
10781
function get(url, bubbleError) {

        /* use url as key for the cache */
        var value = cache.fetch(url)
        var defer = $.Deferred()

        if (value) {
            return defer.resolve(value) /* return a resolved promise with the cached value */
        } else {
            try {
                $.get(url)
                    .done(function(value) {
                        defer.resolve(cache.save(url, decode(value)))
                    }).fail(function(err) {
                        log(err.error)
                    })
            } catch (err) {
                if (bubbleError) {
                    throw new Error(err)
                } else {
                    log(err.error)
                }
            }
        }
        return defer
    }
230576
def cache_key(model, pk):
    ""
    app = model._meta.app_label
    name = model._meta.module_name
    return 'api:{0}:{1}:{2}'.format(app, name, pk)
792575
def loadcache(json_file):
    
    f = open(json_file, 'r')
    data = f.read()
    f.close()
    try:
        apicache = json.loads(data)
    except ValueError as e:
        print("Error processing json:", json_file, e)
        return {}
    return apicache
1309357
def cache_return(func):
    """"""

    _cache = []

    def wrap():
        if not _cache:
            _cache.append(func())
        return _cache[0]
    return wrap
129471
def cached_getter(func):
  """"""
  @wraps(func)
  def wrapper(self):
    attribute = f'_{func.__name__}'
    value = getattr(self, attribute, None)
    if value is None:
      value = func(self)
      setattr(self, attribute, value)
    return value
  return wrapper
992644
def _get(self, *args, **kwargs):
        
        response = requests.get(*args, **kwargs)

        response.raise_for_status()

        return response.json()
184256
def _get_cached_response(self):
        """"""

        if not self._is_cached():
            response = self._download_response()
            self.cache.set_xml(self._get_cache_key(), response)

        return self.cache.get_xml(self._get_cache_key())
781294
def _get_url(method,
             api_url,
             api_version):
    '''
    
    '''
    return '{url}/{version}/{method}.json'.format(url=api_url,
                                                  version=float(api_version),
                                                  method=method)
886671
def data(self):
        """"""
        key = cache_key(self.name)
        data = cache.get(key)
        if data is None:
            logger.debug("Updating package info for %s from PyPI.", self.name)
            data = requests.get(self.url).json()
            cache.set(key, data, PYPI_CACHE_EXPIRY)
        return data
878981
def load(self, key=None):
        # type: (Hashable) -> Promise
        
        if key is None:
            raise TypeError(
                (
                    "The loader.load() function must be called with a value,"
                    + "but got: {}."
                ).format(key)
            )

        cache_key = self.get_cache_key(key)

        # If caching and there is a cache-hit, return cached Promise.
        if self.cache:
            cached_promise = self._promise_cache.get(cache_key)
            if cached_promise:
                return cached_promise

        # Otherwise, produce a new Promise for this value.

        promise = Promise(partial(self.do_resolve_reject, key))  # type: ignore

        # If caching, cache this promise.
        if self.cache:
            self._promise_cache[cache_key] = promise

        return promise