CacheToolsUtils 9.1__tar.gz → 9.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/CacheToolsUtils.egg-info/PKG-INFO +1 -1
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/CacheToolsUtils.py +25 -9
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/PKG-INFO +1 -1
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/pyproject.toml +1 -1
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/CacheToolsUtils.egg-info/SOURCES.txt +0 -0
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/CacheToolsUtils.egg-info/dependency_links.txt +0 -0
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/CacheToolsUtils.egg-info/requires.txt +0 -0
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/CacheToolsUtils.egg-info/top_level.txt +0 -0
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/LICENSE +0 -0
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/MANIFEST.in +0 -0
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/README.md +0 -0
- {cachetoolsutils-9.1 → cachetoolsutils-9.3}/setup.cfg +0 -0
|
@@ -380,10 +380,10 @@ def cached(cache, *args, **kwargs):
|
|
|
380
380
|
|
|
381
381
|
def decorate(fun: Callable):
|
|
382
382
|
|
|
383
|
-
# use cachetools
|
|
383
|
+
# use cachetools "cached" decorator
|
|
384
384
|
fun = cachetools.cached(cache, *args, **kwargs)(fun)
|
|
385
385
|
|
|
386
|
-
# extend
|
|
386
|
+
# extend it with two functions
|
|
387
387
|
def cache_in(*args, **kwargs) -> bool:
|
|
388
388
|
"""Tell whether key is already in cache."""
|
|
389
389
|
key = fun.cache_key(*args, **kwargs) # type: ignore
|
|
@@ -409,12 +409,19 @@ def cached(cache, *args, **kwargs):
|
|
|
409
409
|
MapGen = Callable[[MutableMapping, str], MutableMapping]
|
|
410
410
|
|
|
411
411
|
|
|
412
|
-
def cacheMethods(
|
|
412
|
+
def cacheMethods(
|
|
413
|
+
cache: MutableMapping,
|
|
414
|
+
obj: Any,
|
|
415
|
+
gen: MapGen = PrefixedCache,
|
|
416
|
+
opts: dict[str, Any] = {},
|
|
417
|
+
**funs
|
|
418
|
+
):
|
|
413
419
|
"""Cache some object methods.
|
|
414
420
|
|
|
415
421
|
:param cache: cache to use.
|
|
416
422
|
:param obj: object instance to be cached.
|
|
417
423
|
:param gen: generator of PrefixedCache.
|
|
424
|
+
:param opts: additional parameters when calling `cached`.
|
|
418
425
|
:param funs: name of methods and corresponding prefix
|
|
419
426
|
|
|
420
427
|
.. code-block:: python
|
|
@@ -426,17 +433,22 @@ def cacheMethods(cache: MutableMapping, obj: Any, gen: MapGen = PrefixedCache, *
|
|
|
426
433
|
f = getattr(obj, fun)
|
|
427
434
|
while hasattr(f, "__wrapped__"):
|
|
428
435
|
f = f.__wrapped__
|
|
429
|
-
setattr(obj, fun, cached(cache=gen(cache, prefix))(f))
|
|
436
|
+
setattr(obj, fun, cached(cache=gen(cache, prefix), **opts)(f))
|
|
430
437
|
|
|
431
438
|
|
|
432
439
|
def cacheFunctions(
|
|
433
|
-
cache: MutableMapping,
|
|
440
|
+
cache: MutableMapping,
|
|
441
|
+
globs: MutableMapping[str, Any],
|
|
442
|
+
gen: MapGen = PrefixedCache,
|
|
443
|
+
opts: dict[str, Any] = {},
|
|
444
|
+
**funs
|
|
434
445
|
):
|
|
435
446
|
"""Cache some global functions, with a prefix.
|
|
436
447
|
|
|
437
448
|
:param cache: cache to use.
|
|
438
449
|
:param globs: global object dictionary.
|
|
439
450
|
:param gen: generator of PrefixedCache.
|
|
451
|
+
:param opts: additional parameters when calling `cached`.
|
|
440
452
|
:param funs: name of functions and corresponding prefix
|
|
441
453
|
|
|
442
454
|
.. code-block:: python
|
|
@@ -448,16 +460,20 @@ def cacheFunctions(
|
|
|
448
460
|
f = globs[fun]
|
|
449
461
|
while hasattr(f, "__wrapped__"):
|
|
450
462
|
f = f.__wrapped__
|
|
451
|
-
globs[fun] = cached(cache=gen(cache, prefix))(f)
|
|
463
|
+
globs[fun] = cached(cache=gen(cache, prefix), **opts)(f)
|
|
452
464
|
|
|
453
465
|
|
|
454
466
|
# JSON-based key function
|
|
455
467
|
# NOTE obviously this only works if parameters are json-serializable…
|
|
456
468
|
def json_key(*args, **kwargs):
|
|
457
|
-
if kwargs:
|
|
458
|
-
|
|
469
|
+
if kwargs: # object
|
|
470
|
+
if args:
|
|
471
|
+
val = {"*": args, "**": kwargs}
|
|
472
|
+
else:
|
|
473
|
+
val = {"**": kwargs}
|
|
459
474
|
else: # array
|
|
460
|
-
|
|
475
|
+
val = args
|
|
476
|
+
return json.dumps(val, sort_keys=True, separators=(",", ":"))
|
|
461
477
|
|
|
462
478
|
|
|
463
479
|
# Hmmm…
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|