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:
|
try:
|
||||||
cache.set(ckey, self, timeout=3600)
|
cache.set(ckey, self, timeout=3600)
|
||||||
except TypeError:
|
except Exception:
|
||||||
# Some characters cause issues with caching; ignore and move on
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -554,16 +553,18 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
# Unless otherwise specified, attempt to create the setting
|
# Unless otherwise specified, attempt to create the setting
|
||||||
create = kwargs.pop('create', True)
|
create = kwargs.pop('create', True)
|
||||||
|
|
||||||
|
# Perform cache lookup by default
|
||||||
|
do_cache = kwargs.pop('cache', True)
|
||||||
|
|
||||||
# Prevent saving to the database during data import
|
# Prevent saving to the database during data import
|
||||||
if InvenTree.ready.isImportingData():
|
if InvenTree.ready.isImportingData():
|
||||||
create = False
|
create = False
|
||||||
|
do_cache = False
|
||||||
|
|
||||||
# Prevent saving to the database during migrations
|
# Prevent saving to the database during migrations
|
||||||
if InvenTree.ready.isRunningMigrations():
|
if InvenTree.ready.isRunningMigrations():
|
||||||
create = False
|
create = False
|
||||||
|
do_cache = False
|
||||||
# Perform cache lookup by default
|
|
||||||
do_cache = kwargs.pop('cache', True)
|
|
||||||
|
|
||||||
ckey = cls.create_cache_key(key, **kwargs)
|
ckey = cls.create_cache_key(key, **kwargs)
|
||||||
|
|
||||||
@ -575,7 +576,7 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
if cached_setting is not None:
|
if cached_setting is not None:
|
||||||
return cached_setting
|
return cached_setting
|
||||||
|
|
||||||
except AppRegistryNotReady:
|
except Exception:
|
||||||
# Cache is not ready yet
|
# Cache is not ready yet
|
||||||
do_cache = False
|
do_cache = False
|
||||||
|
|
||||||
|
@ -14,7 +14,10 @@ def currency_code_default():
|
|||||||
"""Returns the default currency code (or USD if not specified)."""
|
"""Returns the default currency code (or USD if not specified)."""
|
||||||
from common.models import InvenTreeSetting
|
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:
|
if cached_value:
|
||||||
return cached_value
|
return cached_value
|
||||||
|
@ -717,7 +717,10 @@ def check_user_role(user, role, permission):
|
|||||||
# First, check the cache
|
# First, check the cache
|
||||||
key = f'role_{user}_{role}_{permission}'
|
key = f'role_{user}_{role}_{permission}'
|
||||||
|
|
||||||
result = cache.get(key)
|
try:
|
||||||
|
result = cache.get(key)
|
||||||
|
except Exception:
|
||||||
|
result = None
|
||||||
|
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user