MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / _get_cache_info

Function _get_cache_info

dwave/cloud/cli.py:1223–1262  ·  view source on GitHub ↗
(config: ClientConfig)

Source from the content-addressed store, hash-verified

1221
1222
1223def _get_cache_info(config: ClientConfig) -> dict[str, list[dict]]:
1224 def _stats(cache: diskcache.Cache) -> dict:
1225 return {
1226 'count': len(cache),
1227 'size': cache.volume(),
1228 }
1229
1230 def _cache(path: Path) -> dict:
1231 with diskcache.Cache(disk=diskcache.JSONDisk, directory=path) as cache:
1232 return dict(path=path) | _stats(cache)
1233
1234 def _creds(path: Path) -> dict:
1235 with Credentials(creds_file=path) as cache:
1236 return dict(path=path) | _stats(cache)
1237
1238 def _existing(paths: list[Path]) -> list[Path]:
1239 return [p for p in paths if p.exists()]
1240
1241 def _path_candidates(subdir: str = '.') -> list[Path]:
1242 paths = set([get_cache_dir()])
1243 if config.cache and config.cache.home:
1244 paths.add(config.cache.home)
1245 return [(Path(p) / subdir).resolve() for p in paths]
1246
1247 return {
1248 # used for solvers, regions
1249 'API cache': [
1250 _cache(path) for path in _existing(_path_candidates('api'))
1251 ],
1252
1253 # used by @cached decorator (not in use currently by cc)
1254 'Function decorator cache': [
1255 _cache(path) for path in _existing(_path_candidates('func'))
1256 ],
1257
1258 # used to store leap auth creds
1259 'Auth credentials cache': [
1260 _creds(Path(path)) for path in _get_creds_paths(only_existing=True)
1261 ],
1262 }
1263
1264
1265@cache.command(name='ls')

Callers 3

cache_listFunction · 0.85
cache_infoFunction · 0.85
cache_purgeFunction · 0.85

Calls 5

_get_creds_pathsFunction · 0.90
_cacheFunction · 0.85
_existingFunction · 0.85
_path_candidatesFunction · 0.85
_credsFunction · 0.85

Tested by

no test coverage detected