MCPcopy Create free account
hub / github.com/modelscope/modelscope / get_from_cache_ms

Function get_from_cache_ms

modelscope/msdatasets/utils/hf_file_utils.py:168–375  ·  view source on GitHub ↗

Given a URL, look for the corresponding file in the local cache. If it's not there, download it. Then return the path to the cached file. Return: Local path (string) Raises: FileNotFoundError: in case of non-recoverable file (non-existent or no cache on

(
    url,
    cache_dir=None,
    force_download=False,
    proxies=None,
    etag_timeout=100,
    resume_download=False,
    user_agent=None,
    local_files_only=False,
    use_etag=True,
    max_retries=3,
    token=None,
    use_auth_token='deprecated',
    ignore_url_params=False,
    storage_options=None,
    download_desc=None,
    disable_tqdm=None,
)

Source from the content-addressed store, hash-verified

166
167
168def get_from_cache_ms(
169 url,
170 cache_dir=None,
171 force_download=False,
172 proxies=None,
173 etag_timeout=100,
174 resume_download=False,
175 user_agent=None,
176 local_files_only=False,
177 use_etag=True,
178 max_retries=3,
179 token=None,
180 use_auth_token='deprecated',
181 ignore_url_params=False,
182 storage_options=None,
183 download_desc=None,
184 disable_tqdm=None,
185) -> str:
186 """
187 Given a URL, look for the corresponding file in the local cache.
188 If it's not there, download it. Then return the path to the cached file.
189
190 Return:
191 Local path (string)
192
193 Raises:
194 FileNotFoundError: in case of non-recoverable file
195 (non-existent or no cache on disk)
196 ConnectionError: in case of unreachable url
197 and no cache on disk
198 """
199 if use_auth_token != 'deprecated':
200 warnings.warn(
201 "'use_auth_token' was deprecated in favor of 'token' in version 2.14.0 and will be removed in 3.0.0.\n"
202 f"You can remove this warning by passing 'token={use_auth_token}' instead.",
203 FutureWarning,
204 )
205 token = use_auth_token
206 if cache_dir is None:
207 cache_dir = MS_DATASETS_CACHE
208 if isinstance(cache_dir, Path):
209 cache_dir = str(cache_dir)
210
211 os.makedirs(cache_dir, exist_ok=True)
212
213 if ignore_url_params:
214 # strip all query parameters and #fragments from the URL
215 cached_url = urljoin(url, urlparse(url).path)
216 else:
217 cached_url = url # additional parameters may be added to the given URL
218
219 connected = False
220 response = None
221 cookies = None
222 etag = None
223 head_error = None
224 scheme = None
225

Callers

nothing calls this directly

Calls 11

HubApiClass · 0.90
http_head_msFunction · 0.85
temp_file_managerFunction · 0.85
http_get_msFunction · 0.85
get_cookiesMethod · 0.80
infoMethod · 0.80
existsMethod · 0.45
getMethod · 0.45
itemsMethod · 0.45
matchMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…