add tenant logic
This commit is contained in:
@@ -2,6 +2,7 @@ import time
|
||||
from typing import Any
|
||||
from sqlalchemy.orm import Session
|
||||
from app.db.cruddb import domainService
|
||||
from app.db.cruddb import tenantService
|
||||
|
||||
class MemoryCache:
|
||||
def __init__(self, max_cache_size: int = 100, ttl: int = 60):
|
||||
@@ -52,4 +53,19 @@ class domainCache:
|
||||
def clear_default_domainurl(self):
|
||||
self.memoryCache.clear()
|
||||
|
||||
domainCacheService =domainCache()
|
||||
domainCacheService =domainCache()
|
||||
|
||||
|
||||
class tenantCache:
|
||||
|
||||
def __init__(self):
|
||||
self.memoryCache = MemoryCache(max_cache_size=50, ttl=120)
|
||||
|
||||
def get_tenant_db(self,db: Session, tenantid: str):
|
||||
if not self.memoryCache.get(f"TENANT_{tenantid}"):
|
||||
tenant = tenantService.get_tenant(db,tenantid)
|
||||
if tenant:
|
||||
self.memoryCache.set(f"TENANT_{tenantid}",tenant.db)
|
||||
return self.memoryCache.get(f"TENANT_{tenantid}")
|
||||
|
||||
tenantCacheService =tenantCache()
|
||||
Reference in New Issue
Block a user