Skip to content

Commit 5c44b6c

Browse files
Remove separate key for invalidating cache
1 parent 87aa83f commit 5c44b6c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

Lib/zipimport.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def __init__(self, path):
9090

9191
if path not in _zip_directory_cache:
9292
_zip_directory_cache[path] = _read_directory(path)
93-
self._cache_is_valid = True
9493
self.archive = path
9594
# a prefix directory following the ZIP file path.
9695
self.prefix = _bootstrap_external._path_join(*prefix[::-1])
@@ -267,24 +266,23 @@ def get_resource_reader(self, fullname):
267266

268267
def _get_files(self):
269268
"""Return the files within the archive path."""
270-
if not self._cache_is_valid:
271-
try:
272-
_zip_directory_cache[self.archive] = _read_directory(self.archive)
273-
except ZipImportError:
274-
_zip_directory_cache.pop(self.archive, None)
275-
self._cache_is_valid = True
276-
277269
try:
278270
files = _zip_directory_cache[self.archive]
279271
except KeyError:
280-
files = {}
272+
try:
273+
files = _zip_directory_cache[self.archive] = _read_directory(self.archive)
274+
except ZipImportError:
275+
files = _zip_directory_cache.pop(self.archive, {})
281276

282277
return files
283278

284279

285280
def invalidate_caches(self):
286281
"""Invalidates the cache of file data of the archive path."""
287-
self._cache_is_valid = False
282+
try:
283+
del _zip_directory_cache[self.archive]
284+
except KeyError:
285+
pass
288286

289287

290288
def __repr__(self):

0 commit comments

Comments
 (0)