Skip to content

Commit 0f30f68

Browse files
committed
implement Attributes.refresh
1 parent 26d7366 commit 0f30f68

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

docs/api/attrs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ The Attributes class (``zarr.attrs``)
1313
.. automethod:: asdict
1414
.. automethod:: put
1515
.. automethod:: update
16+
.. automethod:: refresh

zarr/attrs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def asdict(self):
5555
self._cached_asdict = d
5656
return d
5757

58+
def refresh(self):
59+
"""Refresh cached attributes from the store."""
60+
if self.cache:
61+
self._cached_asdict = self._get_nosync()
62+
5863
def __contains__(self, x):
5964
return x in self.asdict()
6065

zarr/tests/test_attrs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ def test_caching_on(self):
168168
eq(4, store.counter['__getitem__', 'attrs'])
169169
eq(4, store.counter['__setitem__', 'attrs'])
170170

171+
# test refresh()
172+
store['attrs'] = json.dumps(dict(foo='xxx', bar=42)).encode('ascii')
173+
eq(4, store.counter['__getitem__', 'attrs'])
174+
a.refresh()
175+
eq(5, store.counter['__getitem__', 'attrs'])
176+
eq(a['foo'], 'xxx')
177+
eq(5, store.counter['__getitem__', 'attrs'])
178+
eq(a['bar'], 42)
179+
eq(5, store.counter['__getitem__', 'attrs'])
180+
171181
def test_caching_off(self):
172182

173183
# setup store

0 commit comments

Comments
 (0)