Skip to content

Commit d106a25

Browse files
committed
Added a backend cache
1 parent ee68207 commit d106a25

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

audioread/__init__.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,22 @@ def _mad_available():
5959
else:
6060
return True
6161

62+
# A place to store available backends
63+
BACKENDS = []
6264

63-
def available_backends():
64-
"""Returns a list of backends that are available on this system."""
65+
def available_backends(flush_cache=False):
66+
"""Returns a list of backends that are available on this system.
67+
68+
The list of backends is cached after the first call.
69+
If the parameter `flush_cache` is set to `True`, then the cache
70+
will be flushed and the backend list will be reconstructed.
71+
"""
72+
global BACKENDS
73+
if flush:
74+
BACKENDS.clear()
75+
76+
if BACKENDS:
77+
return BACKENDS
6578

6679
# Standard-library WAV and AIFF readers.
6780
from . import rawread
@@ -86,7 +99,10 @@ def available_backends():
8699
if ffdec.available():
87100
result.append(ffdec.FFmpegAudioFile)
88101

89-
return result
102+
# Cache the backends we found
103+
BACKENDS.extend(result)
104+
105+
return BACKENDS
90106

91107

92108
def audio_open(path, backends=None):

0 commit comments

Comments
 (0)