Skip to content

Commit

Permalink
Merge pull request #1368 from girder/improve-cache-guard
Browse files Browse the repository at this point in the history
Improve cache key guard
  • Loading branch information
manthey authored Nov 10, 2023
2 parents f04147d + 9bae994 commit d2c09f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Use minified geojs ([#1362](../../pull/1362))
- Configurable item list grid view ([#1363](../../pull/1363))
- Allow labels in item list view ([#1366](../../pull/1366))
- Improve cache key guard ([#1368](../../pull/1368))

### Bug Fixes
- Default to "None" for the DICOM assetstore limit ([#1359](../../pull/1359))
Expand Down
40 changes: 20 additions & 20 deletions large_image/cache_util/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,27 @@ def __call__(cls, *args, **kwargs): # noqa - N805
return result
except KeyError:
pass
# This conditionally copies a non-styled class and adds a style.
if (kwargs.get('style') and hasattr(cls, '_setStyle') and
kwargs.get('style') != getattr(cls, '_unstyledStyle', None)):
subkwargs = kwargs.copy()
subkwargs['style'] = getattr(cls, '_unstyledStyle', None)
subresult = cls(*args, **subkwargs)
result = subresult.__class__.__new__(subresult.__class__)
with subresult._sourceLock:
result.__dict__ = subresult.__dict__.copy()
result._sourceLock = threading.RLock()
result._classkey = key
# for pickling
result._initValues = (args, kwargs.copy())
result._unstyledInstance = subresult
result._derivedSource = True
# Has to be after setting the _unstyledInstance
result._setStyle(kwargs['style'])
with cacheLock:
cache[key] = result
return result
try:
# This conditionally copies a non-styled class and adds a style.
if (kwargs.get('style') and hasattr(cls, '_setStyle') and
kwargs.get('style') != getattr(cls, '_unstyledStyle', None)):
subkwargs = kwargs.copy()
subkwargs['style'] = getattr(cls, '_unstyledStyle', None)
subresult = cls(*args, **subkwargs)
result = subresult.__class__.__new__(subresult.__class__)
with subresult._sourceLock:
result.__dict__ = subresult.__dict__.copy()
result._sourceLock = threading.RLock()
result._classkey = key
# for pickling
result._initValues = (args, kwargs.copy())
result._unstyledInstance = subresult
result._derivedSource = True
# Has to be after setting the _unstyledInstance
result._setStyle(kwargs['style'])
with cacheLock:
cache[key] = result
return result
instance = super().__call__(*args, **kwargs)
# for pickling
instance._initValues = (args, kwargs.copy())
Expand Down

0 comments on commit d2c09f9

Please sign in to comment.