mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Cache exception handling (#6675)
* Improve cache loading for setting - Handle generic exception - Do not cache if importing data * More generic exception handling * Handle more cache exceptions
This commit is contained in:
parent
8719dd7e1e
commit
f5a42172ac
@ -290,8 +290,7 @@ class BaseInvenTreeSetting(models.Model):
|
||||
|
||||
try:
|
||||
cache.set(ckey, self, timeout=3600)
|
||||
except TypeError:
|
||||
# Some characters cause issues with caching; ignore and move on
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@ -554,16 +553,18 @@ class BaseInvenTreeSetting(models.Model):
|
||||
# Unless otherwise specified, attempt to create the setting
|
||||
create = kwargs.pop('create', True)
|
||||
|
||||
# Perform cache lookup by default
|
||||
do_cache = kwargs.pop('cache', True)
|
||||
|
||||
# Prevent saving to the database during data import
|
||||
if InvenTree.ready.isImportingData():
|
||||
create = False
|
||||
do_cache = False
|
||||
|
||||
# Prevent saving to the database during migrations
|
||||
if InvenTree.ready.isRunningMigrations():
|
||||
create = False
|
||||
|
||||
# Perform cache lookup by default
|
||||
do_cache = kwargs.pop('cache', True)
|
||||
do_cache = False
|
||||
|
||||
ckey = cls.create_cache_key(key, **kwargs)
|
||||
|
||||
@ -575,7 +576,7 @@ class BaseInvenTreeSetting(models.Model):
|
||||
if cached_setting is not None:
|
||||
return cached_setting
|
||||
|
||||
except AppRegistryNotReady:
|
||||
except Exception:
|
||||
# Cache is not ready yet
|
||||
do_cache = False
|
||||
|
||||
|
@ -14,7 +14,10 @@ def currency_code_default():
|
||||
"""Returns the default currency code (or USD if not specified)."""
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
cached_value = cache.get('currency_code_default', '')
|
||||
try:
|
||||
cached_value = cache.get('currency_code_default', '')
|
||||
except Exception:
|
||||
cached_value = None
|
||||
|
||||
if cached_value:
|
||||
return cached_value
|
||||
|
@ -717,7 +717,10 @@ def check_user_role(user, role, permission):
|
||||
# First, check the cache
|
||||
key = f'role_{user}_{role}_{permission}'
|
||||
|
||||
result = cache.get(key)
|
||||
try:
|
||||
result = cache.get(key)
|
||||
except Exception:
|
||||
result = None
|
||||
|
||||
if result is not None:
|
||||
return result
|
||||
|
Loading…
Reference in New Issue
Block a user