Browse Source

moved lock

mertalev 2 years ago
parent
commit
42f5f31b06
1 changed files with 3 additions and 3 deletions
  1. 3 3
      machine-learning/app/models/cache.py

+ 3 - 3
machine-learning/app/models/cache.py

@@ -47,9 +47,9 @@ class ModelCache:
         """
 
         key = self.cache.build_key(model_name, model_type.value)
-        model = await self.cache.get(key)
-        if model is None:
-            async with OptimisticLock(self.cache, key) as lock:
+        async with OptimisticLock(self.cache, key) as lock:
+            model = await self.cache.get(key)
+            if model is None:
                 model = InferenceModel.from_model_type(model_type, model_name, **model_kwargs)
                 await lock.cas(model, ttl=self.ttl)
         return model