|
20 | 20 | import threading
|
21 | 21 | from collections import abc
|
22 | 22 | from collections.abc import Iterator, Mapping, MutableMapping
|
| 23 | +from functools import lru_cache |
23 | 24 | from itertools import chain
|
24 | 25 | from typing import Any
|
25 | 26 |
|
@@ -74,28 +75,24 @@ def exists(name: str) -> bool:
|
74 | 75 | return True if file_found else bool(normalize_locale(name))
|
75 | 76 |
|
76 | 77 |
|
| 78 | +@lru_cache(maxsize=None) |
77 | 79 | def locale_identifiers() -> list[str]:
|
78 | 80 | """Return a list of all locale identifiers for which locale data is
|
79 | 81 | available.
|
80 | 82 |
|
81 |
| - This data is cached after the first invocation in `locale_identifiers.cache`. |
82 |
| -
|
83 |
| - Removing the `locale_identifiers.cache` attribute or setting it to `None` |
84 |
| - will cause this function to re-read the list from disk. |
| 83 | + This data is cached after the first invocation. |
| 84 | + You can clear the cache by calling `locale_identifiers.cache_clear()`. |
85 | 85 |
|
86 | 86 | .. versionadded:: 0.8.1
|
87 | 87 |
|
88 | 88 | :return: a list of locale identifiers (strings)
|
89 | 89 | """
|
90 |
| - data = getattr(locale_identifiers, 'cache', None) |
91 |
| - if data is None: |
92 |
| - locale_identifiers.cache = data = [ |
93 |
| - stem |
94 |
| - for stem, extension in |
95 |
| - (os.path.splitext(filename) for filename in os.listdir(_dirname)) |
96 |
| - if extension == '.dat' and stem != 'root' |
97 |
| - ] |
98 |
| - return data |
| 90 | + return [ |
| 91 | + stem |
| 92 | + for stem, extension in |
| 93 | + (os.path.splitext(filename) for filename in os.listdir(_dirname)) |
| 94 | + if extension == '.dat' and stem != 'root' |
| 95 | + ] |
99 | 96 |
|
100 | 97 |
|
101 | 98 | def load(name: os.PathLike[str] | str, merge_inherited: bool = True) -> dict[str, Any]:
|
|
0 commit comments