CacheToolsUtils 9.2__py3-none-any.whl → 9.3__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CacheToolsUtils
3
- Version: 9.2
3
+ Version: 9.3
4
4
  Summary: Cachetools Utilities
5
5
  Author-email: Fabien Coelho <cachetools.utils@coelho.net>
6
6
  License: CC0
@@ -0,0 +1,6 @@
1
+ CacheToolsUtils.py,sha256=0ZU4Ab8-p_JFl03PaV5lsaih09d9AlV0ftH-X1FAWsc,20623
2
+ CacheToolsUtils-9.3.dist-info/LICENSE,sha256=y_yFW1bmBAUFCF-ZDyDiq10Ykns_19If5pFnZUzYgeU,33
3
+ CacheToolsUtils-9.3.dist-info/METADATA,sha256=_1JhxQFKyP16JdSVmlketndgrw0uB8vEo-18fw_V-QU,4483
4
+ CacheToolsUtils-9.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
5
+ CacheToolsUtils-9.3.dist-info/top_level.txt,sha256=qCyE4jGot5mOmvIQrZueCnPtbYtRe2hqke4sGojm3zI,16
6
+ CacheToolsUtils-9.3.dist-info/RECORD,,
CacheToolsUtils.py CHANGED
@@ -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(cache: MutableMapping, obj: Any, gen: MapGen = PrefixedCache, **funs):
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, globs: MutableMapping[str, Any], gen: MapGen = PrefixedCache, **funs
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,7 +460,7 @@ 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
@@ -1,6 +0,0 @@
1
- CacheToolsUtils.py,sha256=2IzulFpw9WH-7-aJs7cztR-NPdLH3TVMxN2eFyZXRc0,20350
2
- CacheToolsUtils-9.2.dist-info/LICENSE,sha256=y_yFW1bmBAUFCF-ZDyDiq10Ykns_19If5pFnZUzYgeU,33
3
- CacheToolsUtils-9.2.dist-info/METADATA,sha256=jWWKCdp-ShOLRzX4DvYVziFAVdh-JDPA_nvGxK7ZKnE,4483
4
- CacheToolsUtils-9.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
5
- CacheToolsUtils-9.2.dist-info/top_level.txt,sha256=qCyE4jGot5mOmvIQrZueCnPtbYtRe2hqke4sGojm3zI,16
6
- CacheToolsUtils-9.2.dist-info/RECORD,,