fpml 0.3.0__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fpml
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: The FHIRPath mapping language is a data DSL designed to convert data from QuestionnaireResponse (and not only) to any FHIR Resource.
5
5
  License: MIT
6
6
  Keywords: fhir,fhirpath
@@ -201,7 +201,7 @@ Parsing FHIRPath expressions is expensive, so expressions can be compiled once a
201
201
  kept in memory, zero disables caching.
202
202
 
203
203
  Entries are keyed by the expression only, while compilation binds the model and the user-defined
204
- functions, so keep one long-living cache per `fp_options`.
204
+ functions, so keep one long-living cache per `fp_options`. A cache is safe to share between threads.
205
205
 
206
206
  ```python
207
207
  from fhirpathpy.models import models
@@ -169,7 +169,7 @@ Parsing FHIRPath expressions is expensive, so expressions can be compiled once a
169
169
  kept in memory, zero disables caching.
170
170
 
171
171
  Entries are keyed by the expression only, while compilation binds the model and the user-defined
172
- functions, so keep one long-living cache per `fp_options`.
172
+ functions, so keep one long-living cache per `fp_options`. A cache is safe to share between threads.
173
173
 
174
174
  ```python
175
175
  from fhirpathpy.models import models
@@ -1,3 +1,4 @@
1
+ import threading
1
2
  from collections import OrderedDict
2
3
  from typing import Any, Callable, Optional, cast
3
4
 
@@ -21,30 +22,36 @@ class ExpressionCache:
21
22
 
22
23
  Entries are keyed by the expression only, while compilation binds the model
23
24
  and the user-defined functions, so use a separate cache per fp_options.
24
- Zero max size disables caching.
25
+ Zero max size disables caching. Instances are safe to share between threads.
25
26
  """
26
27
 
27
28
  def __init__(self, max_size: int) -> None:
28
29
  self.max_size = max_size
29
30
  self._compiled: OrderedDict[str, CompiledExpression] = OrderedDict()
31
+ self._lock = threading.Lock()
30
32
 
31
33
  def compile(self, expression: str, fp_options: Optional[FPOptions]) -> CompiledExpression:
32
- cached = self._compiled.get(expression)
33
- if cached is not None:
34
- self._compiled.move_to_end(expression)
34
+ with self._lock:
35
+ cached = self._compiled.get(expression)
36
+ if cached is not None:
37
+ self._compiled.move_to_end(expression)
35
38
 
36
- return cached
39
+ return cached
37
40
 
41
+ # Compiling outside the lock, so that it does not hold up the other threads
38
42
  compiled = compile_expression(expression, fp_options)
43
+
39
44
  if self.max_size > 0:
40
- self._compiled[expression] = compiled
41
- if len(self._compiled) > self.max_size:
42
- self._compiled.popitem(last=False)
45
+ with self._lock:
46
+ self._compiled[expression] = compiled
47
+ if len(self._compiled) > self.max_size:
48
+ self._compiled.popitem(last=False)
43
49
 
44
50
  return compiled
45
51
 
46
52
  def clear(self) -> None:
47
- self._compiled.clear()
53
+ with self._lock:
54
+ self._compiled.clear()
48
55
 
49
56
  @property
50
57
  def size(self) -> int:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fpml"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "The FHIRPath mapping language is a data DSL designed to convert data from QuestionnaireResponse (and not only) to any FHIR Resource."
5
5
  authors = [{ name = "Beda Software", email = "ilya@beda.software" }]
6
6
  maintainers = [
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes