File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,3 +13,4 @@ The Attributes class (``zarr.attrs``)
1313 .. automethod :: asdict
1414 .. automethod :: put
1515 .. automethod :: update
16+ .. automethod :: refresh
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments