def _fetch_instance(self): """Fetch the underlying instance. """ if not self._instance: # Try to find it in the cache self._instance = CLIENT_INSTANCE_CACHE.get(self._url, None) if not self._instance: # We now have a cache miss so construct a new connector self._instance = _InstanceConnector( self._url, **self._fields) if CLIENT_INSTANCE_CACHE.enabled: CLIENT_INSTANCE_CACHE[self._url] = self._instance
def _fetch_instance(self): """Fetch the underlying instance. """ from slumber import _client for candidate in getattr(_client, '_instances', []): candidate_url = from_slumber_scheme(candidate._url) self_url = from_slumber_scheme(self._url) if candidate_url == self_url: return candidate instance = CLIENT_INSTANCE_CACHE.get(self._url, None) if not instance: # We now have a cache miss so construct a new connector instance = _InstanceConnector(self._url, **self._fields) if CLIENT_INSTANCE_CACHE.enabled: CLIENT_INSTANCE_CACHE[self._url] = instance return instance
def _flush_client_instance_cache(cls): """Flush the (global) instance cache. """ CLIENT_INSTANCE_CACHE.clear()