File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -13,3 +13,4 @@ The Attributes class (``zarr.attrs``)
13
13
.. automethod :: asdict
14
14
.. automethod :: put
15
15
.. automethod :: update
16
+ .. automethod :: refresh
Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ def asdict(self):
55
55
self ._cached_asdict = d
56
56
return d
57
57
58
+ def refresh (self ):
59
+ """Refresh cached attributes from the store."""
60
+ if self .cache :
61
+ self ._cached_asdict = self ._get_nosync ()
62
+
58
63
def __contains__ (self , x ):
59
64
return x in self .asdict ()
60
65
Original file line number Diff line number Diff line change @@ -168,6 +168,16 @@ def test_caching_on(self):
168
168
eq (4 , store .counter ['__getitem__' , 'attrs' ])
169
169
eq (4 , store .counter ['__setitem__' , 'attrs' ])
170
170
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
+
171
181
def test_caching_off (self ):
172
182
173
183
# setup store
You can’t perform that action at this time.
0 commit comments