2
2
import abc
3
3
from collections import defaultdict
4
4
from contextlib import contextmanager
5
- from enum import Enum , auto
5
+ from enum import Enum , Flag , auto
6
6
from sys import modules
7
7
8
8
from ansys .api .edb .v1 .edb_messages_pb2 import EDBObjCollectionMessage , EDBObjMessage
@@ -77,6 +77,7 @@ def __init__(self):
77
77
self ._response_cache = {}
78
78
self ._msg_type_cache = {}
79
79
self ._cached_edb_objs = {}
80
+ self ._allow_invalidation = True
80
81
81
82
def _extract_msg_from_any_module_msg (self , any_module_msg ):
82
83
msg_type_name = any_module_msg .any .TypeName ()
@@ -126,7 +127,7 @@ def _hijack_request(self, service_name, rpc_name, request):
126
127
return self ._response_cache .get (self ._generate_cache_key (service_name , rpc_name , request ))
127
128
128
129
def invalidate (self ):
129
- if not self ._response_cache :
130
+ if not self ._response_cache or not self . allow_invalidation :
130
131
return
131
132
self ._response_cache .clear ()
132
133
self ._cached_edb_objs = self ._cached_edb_objs .fromkeys (self ._cached_edb_objs , False )
@@ -153,6 +154,14 @@ def refresh_for_request(self):
153
154
for msg in response .items :
154
155
self .add_from_cache_msg (msg )
155
156
157
+ @property
158
+ def allow_invalidation (self ):
159
+ return self ._allow_invalidation
160
+
161
+ @allow_invalidation .setter
162
+ def allow_invalidation (self , allow ):
163
+ self ._allow_invalidation = allow
164
+
156
165
157
166
class _Buffer (_IOOptimizer ):
158
167
class _BufferEntry :
@@ -181,6 +190,7 @@ def _reset(self):
181
190
self ._buffer = []
182
191
self ._futures = defaultdict (list )
183
192
self ._invalidate_cache = False
193
+ self ._allow_flushing = True
184
194
185
195
def _hijack_request (self , service_name , rpc_name , request ):
186
196
if (rpc_info := get_rpc_info (service_name , rpc_name )) is None or rpc_info .is_read :
@@ -203,7 +213,7 @@ def _buffer_request_iterator(buffer):
203
213
)
204
214
205
215
def flush (self ):
206
- if not self ._buffer :
216
+ if not self ._buffer or not self . allow_flushing :
207
217
return
208
218
with self .block ():
209
219
if (cache := get_cache ()) is not None and self ._invalidate_cache :
@@ -225,6 +235,14 @@ def add_future_ref(self, future):
225
235
def _reset_after_block (self ):
226
236
self ._reset ()
227
237
238
+ @property
239
+ def allow_flushing (self ):
240
+ return self ._allow_flushing
241
+
242
+ @allow_flushing .setter
243
+ def allow_flushing (self , allow ):
244
+ self ._allow_flushing = allow
245
+
228
246
229
247
class ServerNotification (Enum ):
230
248
"""Provides an enum representing the types of server notifications."""
@@ -234,12 +252,15 @@ class ServerNotification(Enum):
234
252
RESET_FUTURE_TRACKING = auto ()
235
253
236
254
237
- class IOMangementType (Enum ):
255
+ class IOMangementType (Flag ):
238
256
"""Provides an enum representing the types of IO management modes."""
239
257
240
258
READ = auto ()
241
259
WRITE = auto ()
242
- READ_AND_WRITE = auto ()
260
+ READ_AND_WRITE = READ | WRITE
261
+ NO_CACHE_INVALIDATION = auto ()
262
+ NO_BUFFER_FLUSHING = auto ()
263
+ NO_CACHE_INVALIDATION_NO_BUFFER_FLUSHING = NO_CACHE_INVALIDATION | NO_BUFFER_FLUSHING
243
264
244
265
245
266
class _ActiveRequestEdbObjMsgMgr :
@@ -286,16 +307,21 @@ def _enable_caching(enable):
286
307
_get_io_manager_stub ().EnableCache (bool_message (enable ))
287
308
288
309
def start_managing (self , mode ):
289
- if mode == IOMangementType .READ or mode == IOMangementType . READ_AND_WRITE :
310
+ if IOMangementType .READ in mode :
290
311
self ._cache = _Cache ()
291
312
self ._enable_caching (True )
292
- if mode == IOMangementType .WRITE or mode == IOMangementType . READ_AND_WRITE :
313
+ if IOMangementType .WRITE in mode :
293
314
self ._buffer = _Buffer ()
315
+ if IOMangementType .NO_CACHE_INVALIDATION in mode :
316
+ self ._cache .allow_invalidation = False
317
+ if IOMangementType .NO_BUFFER_FLUSHING in mode :
318
+ self ._buffer .allow_flushing = False
294
319
295
320
def end_managing (self ):
296
321
if self ._cache is not None :
297
322
self ._enable_caching (False )
298
323
if self ._buffer is not None :
324
+ self ._buffer .allow_flushing = True
299
325
self ._buffer .flush ()
300
326
self ._reset ()
301
327
0 commit comments