Skip to content

Commit 4fa7c07

Browse files
authored
Merge pull request #126 from bmcfee/backend-cache
Backend cache
2 parents ee68207 + b770246 commit 4fa7c07

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

audioread/__init__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,19 @@ 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+
73+
if BACKENDS and not flush_cache:
74+
return BACKENDS
6575

6676
# Standard-library WAV and AIFF readers.
6777
from . import rawread
@@ -86,7 +96,10 @@ def available_backends():
8696
if ffdec.available():
8797
result.append(ffdec.FFmpegAudioFile)
8898

89-
return result
99+
# Cache the backends we found
100+
BACKENDS[:] = result
101+
102+
return BACKENDS
90103

91104

92105
def audio_open(path, backends=None):

0 commit comments

Comments
 (0)