Skip to content

Commit 3da89aa

Browse files
committed
Cache get_path
1 parent aadecdc commit 3da89aa

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/ess/reduce/data.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)
33

4+
from functools import cache
45
from pathlib import Path
56

67

@@ -31,9 +32,19 @@ def __contains__(self, key: str) -> bool:
3132
"""Return True if the key is in the registry."""
3233
return key in self._registry.registry
3334

35+
@cache # noqa: B019
3436
def get_path(self, name: str, unzip: bool = False) -> Path:
35-
"""
36-
Get the path to a file in the registry.
37+
"""Get the path to a file in the registry.
38+
39+
Downloads the file if necessary.
40+
41+
Note that return values of this method are cached to avoid recomputing
42+
potentially expensive checksums.
43+
This usually means that the ``Registry`` object itself gets stored until the
44+
Python interpreter shuts down.
45+
However, registries are small and do not own resources.
46+
It is anyway expected that the registry objects are stored at
47+
module scope and live until program exit.
3748
3849
Parameters
3950
----------

0 commit comments

Comments
 (0)