Skip to content

Commit

Permalink
Merge pull request #722 from ianco/master
Browse files Browse the repository at this point in the history
Force reload of cred type cache periodically
  • Loading branch information
WadeBarnes authored Dec 20, 2021
2 parents 928e784 + 3527113 commit b12cae9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion server/vcr-server/agent_webhooks/utils/credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import uuid
from collections import namedtuple
from datetime import datetime
from datetime import datetime, timedelta
from importlib import import_module
import os

Expand Down Expand Up @@ -58,6 +58,8 @@
print(">>> NO not creating detail claims for credentials")
CREATE_CREDENTIAL_CLAIMS = False

CTYPE_CACHE_MAX_AGE_MINS = int(os.environ.get('CTYPE_CACHE_MAX_AGE_MINS', '10'))


def schema_key(s_id: str) -> SchemaKey:
"""
Expand Down Expand Up @@ -259,7 +261,17 @@ class CredentialManager(object):
"""

def __init__(self) -> None:
self._init_ctype_cache()

def _init_ctype_cache(self):
self._cred_type_cache = {}
self._cred_type_cache_created = datetime.now()
self._cred_type_cache_max_age = (self._cred_type_cache_created +
timedelta(minutes=CTYPE_CACHE_MAX_AGE_MINS))

def _reinit_ctype_cache(self):
if self._cred_type_cache_max_age < datetime.now():
self._init_ctype_cache()

@classmethod
def get_claims(cls, credential):
Expand Down Expand Up @@ -356,6 +368,10 @@ def get_credential_type(self, credential: (Credential, CredentialModel)):
Fetch the credential type for the incoming credential
"""
LOGGER.debug(">>> get credential context")

# force re-init to get any issuer updates
self._reinit_ctype_cache()

start_time = time.perf_counter()
result = None
type_id = getattr(credential, "credential_type_id", None)
Expand Down

0 comments on commit b12cae9

Please sign in to comment.