glasskit
Advanced tools
| Metadata-Version: 1.0 | ||
| Name: glasskit | ||
| Version: 3.11.6 | ||
| Version: 3.11.7 | ||
| Summary: a micro webframework based on flask and pymongo | ||
@@ -5,0 +5,0 @@ Home-page: https://gitlab.com/viert/glasskit |
+73
-34
@@ -11,3 +11,3 @@ import functools | ||
| DEFAULT_CACHE_PREFIX = 'uengine' | ||
| DEFAULT_CACHE_PREFIX = "uengine" | ||
| DEFAULT_CACHE_TIMEOUT = 3600 | ||
@@ -17,3 +17,2 @@ | ||
| class RequestLocalCache: | ||
| @staticmethod | ||
@@ -49,3 +48,3 @@ def has(key): | ||
| md5(str(args).encode("utf-8")).hexdigest(), | ||
| md5(str(kwargs).encode("utf-8")).hexdigest() | ||
| md5(str(kwargs).encode("utf-8")).hexdigest(), | ||
| ) | ||
@@ -66,3 +65,7 @@ | ||
| def cached_function(cache_key_prefix=DEFAULT_CACHE_PREFIX, cache_timeout=DEFAULT_CACHE_TIMEOUT, positive_only=False): | ||
| def cached_function( | ||
| cache_key_prefix=DEFAULT_CACHE_PREFIX, | ||
| cache_timeout=DEFAULT_CACHE_TIMEOUT, | ||
| positive_only=False, | ||
| ): | ||
| def cache_decorator(func): | ||
@@ -72,3 +75,4 @@ @functools.wraps(func) | ||
| cache_key, _ = _generate_function_cache_key( | ||
| cache_key_prefix, func.__name__, args, kwargs) | ||
| cache_key_prefix, func.__name__, args, kwargs | ||
| ) | ||
| t1 = datetime.now() | ||
@@ -78,4 +82,7 @@ | ||
| value = ctx.cache.get(cache_key) | ||
| ctx.log.debug("Cache HIT %s (%.3f seconds)", | ||
| cache_key, (datetime.now() - t1).total_seconds()) | ||
| ctx.log.debug( | ||
| "Cache HIT %s (%.3f seconds)", | ||
| cache_key, | ||
| (datetime.now() - t1).total_seconds(), | ||
| ) | ||
| else: | ||
@@ -85,6 +92,11 @@ value = func(*args, **kwargs) | ||
| ctx.cache.set(cache_key, value, timeout=cache_timeout) | ||
| ctx.log.debug("Cache MISS %s (%.3f seconds)", | ||
| cache_key, (datetime.now() - t1).total_seconds()) | ||
| ctx.log.debug( | ||
| "Cache MISS %s (%.3f seconds)", | ||
| cache_key, | ||
| (datetime.now() - t1).total_seconds(), | ||
| ) | ||
| return value | ||
| return wrapper | ||
| return cache_decorator | ||
@@ -102,3 +114,4 @@ | ||
| ctx.log.error( | ||
| f"MethodCache ERROR {obj.__class__.__name__} doesn't have attr {key_field}") | ||
| f"MethodCache ERROR {obj.__class__.__name__} doesn't have attr {key_field}" | ||
| ) | ||
| return func(*args, **kwargs) | ||
@@ -108,4 +121,3 @@ try: | ||
| except TypeError as e: | ||
| ctx.log.error( | ||
| f"MethodCache ERROR parsing {key_field}: {e}") | ||
| ctx.log.error(f"MethodCache ERROR parsing {key_field}: {e}") | ||
| return func(*args, **kwargs) | ||
@@ -119,4 +131,7 @@ | ||
| value = ctx.cache.get(cache_key) | ||
| ctx.log.debug("MethodCache HIT %s (%.3f seconds)", | ||
| cache_key, (datetime.now() - t1).total_seconds()) | ||
| ctx.log.debug( | ||
| "MethodCache HIT %s (%.3f seconds)", | ||
| cache_key, | ||
| (datetime.now() - t1).total_seconds(), | ||
| ) | ||
| else: | ||
@@ -126,4 +141,7 @@ value = func(*args, **kwargs) | ||
| ctx.cache.set(cache_key, value, timeout=cache_timeout) | ||
| ctx.log.debug("MethodCache MISS %s (%.3f seconds)", | ||
| cache_key, (datetime.now() - t1).total_seconds()) | ||
| ctx.log.debug( | ||
| "MethodCache MISS %s (%.3f seconds)", | ||
| cache_key, | ||
| (datetime.now() - t1).total_seconds(), | ||
| ) | ||
@@ -133,2 +151,3 @@ return value | ||
| return wrapper | ||
| return decorator | ||
@@ -138,4 +157,4 @@ | ||
| def check_cache(): | ||
| k = md5(str(randint(0, 1000000)).encode('utf-8')).hexdigest() | ||
| v = md5(str(randint(0, 1000000)).encode('utf-8')).hexdigest() | ||
| k = md5(str(randint(0, 1000000)).encode("utf-8")).hexdigest() | ||
| v = md5(str(randint(0, 1000000)).encode("utf-8")).hexdigest() | ||
| ctx.cache.set(k, v) | ||
@@ -156,2 +175,4 @@ if ctx.cache.get(k) != v: | ||
| """ | ||
| rtc = RequestLocalCache() | ||
| def cache_decorator(func): | ||
@@ -164,16 +185,27 @@ @functools.wraps(func) | ||
| flag_key, _ = _generate_function_cache_key( | ||
| cache_key_prefix, func.__name__, args, kwargs) | ||
| cache_key_prefix, func.__name__, args, kwargs | ||
| ) | ||
| t1 = datetime.now() | ||
| if not req_cache_has_key(flag_key): | ||
| if not rtc.has(flag_key): | ||
| func(*args, **kwargs) | ||
| req_cache_set(flag_key, True) | ||
| rtc.set(flag_key, True) | ||
| ts = (datetime.now() - t1).total_seconds() | ||
| ctx.log.debug("OncePerRequest MISS %s(%s) (%.3f secs)", func.__name__, | ||
| flag_key, ts) | ||
| ctx.log.debug( | ||
| "OncePerRequest MISS %s(%s) (%.3f secs)", | ||
| func.__name__, | ||
| flag_key, | ||
| ts, | ||
| ) | ||
| else: | ||
| ts = (datetime.now() - t1).total_seconds() | ||
| ctx.log.debug("OncePerRequest HIT %s(%s) (%.3f secs)", func.__name__, | ||
| flag_key, ts) | ||
| ctx.log.debug( | ||
| "OncePerRequest HIT %s(%s) (%.3f secs)", | ||
| func.__name__, | ||
| flag_key, | ||
| ts, | ||
| ) | ||
| return wrapper | ||
| return cache_decorator | ||
@@ -191,2 +223,4 @@ | ||
| """ | ||
| rtc = RequestLocalCache() | ||
| def cache_decorator(func): | ||
@@ -198,21 +232,26 @@ @functools.wraps(func) | ||
| cache_key, _ = _get_cache_key( | ||
| cache_key_prefix, func.__name__, args, kwargs) | ||
| cache_key, _ = _generate_function_cache_key( | ||
| cache_key_prefix, func.__name__, args, kwargs | ||
| ) | ||
| t1 = datetime.now() | ||
| if not req_cache_has_key(cache_key): | ||
| if not rtc.has(cache_key): | ||
| value = func(*args, **kwargs) | ||
| req_cache_set(cache_key, value) | ||
| rtc.set(cache_key, value) | ||
| ts = (datetime.now() - t1).total_seconds() | ||
| ctx.log.debug("RTCache MISS %s(%s) (%.3f secs)", | ||
| func.__name__, cache_key, ts) | ||
| ctx.log.debug( | ||
| "RTCache MISS %s(%s) (%.3f secs)", func.__name__, cache_key, ts | ||
| ) | ||
| else: | ||
| value = req_cache_get(cache_key) | ||
| value = rtc.get(cache_key) | ||
| if isinstance(value, ObjectsCursor): | ||
| value.cursor.rewind() | ||
| ts = (datetime.now() - t1).total_seconds() | ||
| ctx.log.debug("RTCache HIT %s(%s) (%.3f secs)", | ||
| func.__name__, cache_key, ts) | ||
| ctx.log.debug( | ||
| "RTCache HIT %s(%s) (%.3f secs)", func.__name__, cache_key, ts | ||
| ) | ||
| return value | ||
| return wrapper | ||
| return cache_decorator | ||
@@ -219,0 +258,0 @@ |
+1
-1
| Metadata-Version: 1.0 | ||
| Name: glasskit | ||
| Version: 3.11.6 | ||
| Version: 3.11.7 | ||
| Summary: a micro webframework based on flask and pymongo | ||
@@ -5,0 +5,0 @@ Home-page: https://gitlab.com/viert/glasskit |
+1
-1
@@ -6,3 +6,3 @@ from setuptools import setup, find_packages | ||
| name="glasskit", | ||
| version="3.11.6", | ||
| version="3.11.7", | ||
| description="a micro webframework based on flask and pymongo", | ||
@@ -9,0 +9,0 @@ url="https://gitlab.com/viert/glasskit", |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
164696
0.27%4027
0.78%