cachier 2.3.0__tar.gz → 3.0.1__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.
- {cachier-2.3.0 → cachier-3.0.1}/MANIFEST.in +3 -3
- {cachier-2.3.0/cachier.egg-info → cachier-3.0.1}/PKG-INFO +38 -21
- {cachier-2.3.0 → cachier-3.0.1}/README.rst +7 -7
- cachier-3.0.1/pyproject.toml +176 -0
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/__init__.py +2 -2
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/__main__.py +1 -1
- cachier-3.0.1/src/cachier/_types.py +9 -0
- cachier-3.0.1/src/cachier/config.py +103 -0
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/core.py +66 -132
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/cores/base.py +40 -25
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/cores/memory.py +16 -13
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/cores/mongo.py +47 -35
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/cores/pickle.py +79 -109
- cachier-3.0.1/src/cachier/version.info +1 -0
- {cachier-2.3.0 → cachier-3.0.1/src/cachier.egg-info}/PKG-INFO +38 -21
- cachier-3.0.1/src/cachier.egg-info/SOURCES.txt +23 -0
- cachier-3.0.1/src/cachier.egg-info/entry_points.txt +2 -0
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier.egg-info/requires.txt +1 -2
- cachier-2.3.0/cachier/version.info +0 -1
- cachier-2.3.0/cachier.egg-info/SOURCES.txt +0 -23
- cachier-2.3.0/cachier.egg-info/entry_points.txt +0 -2
- cachier-2.3.0/pyproject.toml +0 -78
- cachier-2.3.0/requirements.txt +0 -3
- cachier-2.3.0/setup.py +0 -84
- {cachier-2.3.0 → cachier-3.0.1}/LICENSE +0 -0
- {cachier-2.3.0 → cachier-3.0.1}/setup.cfg +0 -0
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/_version.py +0 -0
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/cores/__init__.py +0 -0
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier/py.typed +0 -0
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier.egg-info/dependency_links.txt +0 -0
- {cachier-2.3.0 → cachier-3.0.1/src}/cachier.egg-info/top_level.txt +0 -0
@@ -1,9 +1,9 @@
|
|
1
1
|
# Manifest syntax https://docs.python.org/2/distutils/sourcedist.html
|
2
2
|
graft wheelhouse
|
3
3
|
|
4
|
-
recursive-
|
5
|
-
include cachier/version.info
|
4
|
+
recursive-include src *.info
|
6
5
|
include README.rst
|
7
|
-
include
|
6
|
+
include LICENSE
|
8
7
|
|
8
|
+
prune __pycache__
|
9
9
|
prune tests
|
@@ -1,33 +1,50 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: cachier
|
3
|
-
Version:
|
3
|
+
Version: 3.0.1
|
4
4
|
Summary: Persistent, stale-free, local and cross-machine caching for Python functions.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
Author-email: Shay Palachy Affek <shay.palachy@gmail.com>
|
6
|
+
License: MIT License
|
7
|
+
|
8
|
+
Copyright (c) 2016 Shay Palachy
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
12
|
+
in the Software without restriction, including without limitation the rights
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
15
|
+
furnished to do so, subject to the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
SOFTWARE.
|
27
|
+
|
28
|
+
Project-URL: Source, https://github.com/python-cachier/cachier
|
29
|
+
Keywords: cache,caching,cross-machine,decorator,local,memoization,mongo,persistent
|
13
30
|
Classifier: Development Status :: 4 - Beta
|
31
|
+
Classifier: Intended Audience :: Developers
|
14
32
|
Classifier: License :: OSI Approved :: MIT License
|
15
33
|
Classifier: Programming Language :: Python
|
16
|
-
Classifier: Programming Language :: Python :: 3
|
34
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
17
35
|
Classifier: Programming Language :: Python :: 3.8
|
18
36
|
Classifier: Programming Language :: Python :: 3.9
|
19
37
|
Classifier: Programming Language :: Python :: 3.10
|
20
38
|
Classifier: Programming Language :: Python :: 3.11
|
21
39
|
Classifier: Programming Language :: Python :: 3.12
|
40
|
+
Classifier: Topic :: Other/Nonlisted Topic
|
22
41
|
Classifier: Topic :: Software Development :: Libraries
|
23
42
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
24
43
|
Classifier: Topic :: Utilities
|
25
|
-
|
26
|
-
Classifier: Intended Audience :: Developers
|
44
|
+
Description-Content-Type: text/x-rst
|
27
45
|
License-File: LICENSE
|
28
|
-
Requires-Dist: watchdog>=2.3.1
|
29
46
|
Requires-Dist: portalocker>=2.3.2
|
30
|
-
Requires-Dist:
|
47
|
+
Requires-Dist: watchdog>=2.3.1
|
31
48
|
|
32
49
|
Cachier
|
33
50
|
#######
|
@@ -267,7 +284,7 @@ Cachier also accepts several keyword arguments in the calls of the function it w
|
|
267
284
|
Ignore Cache
|
268
285
|
~~~~~~~~~~~~
|
269
286
|
|
270
|
-
You can have ``cachier`` ignore any existing cache for a specific function call by passing ``
|
287
|
+
You can have ``cachier`` ignore any existing cache for a specific function call by passing ``cachier__skip_cache=True`` to the function call. The cache will neither be checked nor updated with the new return value.
|
271
288
|
|
272
289
|
.. code-block:: python
|
273
290
|
|
@@ -276,17 +293,17 @@ You can have ``cachier`` ignore any existing cache for a specific function call
|
|
276
293
|
return first_num + second_num
|
277
294
|
|
278
295
|
def main():
|
279
|
-
print(sum(5, 3,
|
296
|
+
print(sum(5, 3, cachier__skip_cache=True))
|
280
297
|
|
281
298
|
Overwrite Cache
|
282
299
|
~~~~~~~~~~~~~~~
|
283
300
|
|
284
|
-
You can have ``cachier`` overwrite an existing cache entry - if one exists - for a specific function call by passing ``
|
301
|
+
You can have ``cachier`` overwrite an existing cache entry - if one exists - for a specific function call by passing ``cachier__overwrite_cache=True`` to the function call. The cache will not be checked but will be updated with the new return value.
|
285
302
|
|
286
303
|
Verbose Cache Call
|
287
304
|
~~~~~~~~~~~~~~~~~~
|
288
305
|
|
289
|
-
You can have ``cachier`` print out a detailed explanation of the logic of a specific call by passing ``
|
306
|
+
You can have ``cachier`` print out a detailed explanation of the logic of a specific call by passing ``cachier__verbose=True`` to the function call. This can be useful if you are not sure why a certain function result is, or is not, returned.
|
290
307
|
|
291
308
|
Cache `None` Values
|
292
309
|
~~~~~~~~~~~~~~~~~~~
|
@@ -435,7 +452,7 @@ To run all tests EXCEPT memory core AND MongoDB core related tests, use:
|
|
435
452
|
Running MongoDB tests against a live MongoDB instance
|
436
453
|
-----------------------------------------------------
|
437
454
|
|
438
|
-
**Note to developers:** By default, all MongoDB tests are run against a mocked MongoDB instance, provided by the ``pymongo_inmemory`` package. To run them against a live MongoDB instance, the ``
|
455
|
+
**Note to developers:** By default, all MongoDB tests are run against a mocked MongoDB instance, provided by the ``pymongo_inmemory`` package. To run them against a live MongoDB instance, the ``CACHIER_TEST_VS_DOCKERIZED_MONGO`` environment variable is set to ``True`` in the ``test`` environment of this repository (and additional environment variables are populated with the appropriate credentials), used by the GitHub Action running tests on every commit and pull request.
|
439
456
|
|
440
457
|
Contributors are not expected to run these tests against a live MongoDB instance when developing, as credentials for the testing instance used will NOT be shared, but rather use the testing against the in-memory MongoDB instance as a good proxy.
|
441
458
|
|
@@ -492,8 +509,8 @@ Notable bugfixers:
|
|
492
509
|
.. |PyPI-Versions| image:: https://img.shields.io/pypi/pyversions/cachier.svg
|
493
510
|
:target: https://pypi.python.org/pypi/cachier
|
494
511
|
|
495
|
-
.. |Build-Status| image:: https://github.com/python-cachier/cachier/actions/workflows/test.yml/badge.svg
|
496
|
-
:target: https://github.com/python-cachier/cachier/actions/workflows/test.yml
|
512
|
+
.. |Build-Status| image:: https://github.com/python-cachier/cachier/actions/workflows/ci-test.yml/badge.svg
|
513
|
+
:target: https://github.com/python-cachier/cachier/actions/workflows/ci-test.yml
|
497
514
|
|
498
515
|
.. |LICENCE| image:: https://img.shields.io/pypi/l/cachier.svg
|
499
516
|
:target: https://pypi.python.org/pypi/cachier
|
@@ -236,7 +236,7 @@ Cachier also accepts several keyword arguments in the calls of the function it w
|
|
236
236
|
Ignore Cache
|
237
237
|
~~~~~~~~~~~~
|
238
238
|
|
239
|
-
You can have ``cachier`` ignore any existing cache for a specific function call by passing ``
|
239
|
+
You can have ``cachier`` ignore any existing cache for a specific function call by passing ``cachier__skip_cache=True`` to the function call. The cache will neither be checked nor updated with the new return value.
|
240
240
|
|
241
241
|
.. code-block:: python
|
242
242
|
|
@@ -245,17 +245,17 @@ You can have ``cachier`` ignore any existing cache for a specific function call
|
|
245
245
|
return first_num + second_num
|
246
246
|
|
247
247
|
def main():
|
248
|
-
print(sum(5, 3,
|
248
|
+
print(sum(5, 3, cachier__skip_cache=True))
|
249
249
|
|
250
250
|
Overwrite Cache
|
251
251
|
~~~~~~~~~~~~~~~
|
252
252
|
|
253
|
-
You can have ``cachier`` overwrite an existing cache entry - if one exists - for a specific function call by passing ``
|
253
|
+
You can have ``cachier`` overwrite an existing cache entry - if one exists - for a specific function call by passing ``cachier__overwrite_cache=True`` to the function call. The cache will not be checked but will be updated with the new return value.
|
254
254
|
|
255
255
|
Verbose Cache Call
|
256
256
|
~~~~~~~~~~~~~~~~~~
|
257
257
|
|
258
|
-
You can have ``cachier`` print out a detailed explanation of the logic of a specific call by passing ``
|
258
|
+
You can have ``cachier`` print out a detailed explanation of the logic of a specific call by passing ``cachier__verbose=True`` to the function call. This can be useful if you are not sure why a certain function result is, or is not, returned.
|
259
259
|
|
260
260
|
Cache `None` Values
|
261
261
|
~~~~~~~~~~~~~~~~~~~
|
@@ -404,7 +404,7 @@ To run all tests EXCEPT memory core AND MongoDB core related tests, use:
|
|
404
404
|
Running MongoDB tests against a live MongoDB instance
|
405
405
|
-----------------------------------------------------
|
406
406
|
|
407
|
-
**Note to developers:** By default, all MongoDB tests are run against a mocked MongoDB instance, provided by the ``pymongo_inmemory`` package. To run them against a live MongoDB instance, the ``
|
407
|
+
**Note to developers:** By default, all MongoDB tests are run against a mocked MongoDB instance, provided by the ``pymongo_inmemory`` package. To run them against a live MongoDB instance, the ``CACHIER_TEST_VS_DOCKERIZED_MONGO`` environment variable is set to ``True`` in the ``test`` environment of this repository (and additional environment variables are populated with the appropriate credentials), used by the GitHub Action running tests on every commit and pull request.
|
408
408
|
|
409
409
|
Contributors are not expected to run these tests against a live MongoDB instance when developing, as credentials for the testing instance used will NOT be shared, but rather use the testing against the in-memory MongoDB instance as a good proxy.
|
410
410
|
|
@@ -461,8 +461,8 @@ Notable bugfixers:
|
|
461
461
|
.. |PyPI-Versions| image:: https://img.shields.io/pypi/pyversions/cachier.svg
|
462
462
|
:target: https://pypi.python.org/pypi/cachier
|
463
463
|
|
464
|
-
.. |Build-Status| image:: https://github.com/python-cachier/cachier/actions/workflows/test.yml/badge.svg
|
465
|
-
:target: https://github.com/python-cachier/cachier/actions/workflows/test.yml
|
464
|
+
.. |Build-Status| image:: https://github.com/python-cachier/cachier/actions/workflows/ci-test.yml/badge.svg
|
465
|
+
:target: https://github.com/python-cachier/cachier/actions/workflows/ci-test.yml
|
466
466
|
|
467
467
|
.. |LICENCE| image:: https://img.shields.io/pypi/l/cachier.svg
|
468
468
|
:target: https://pypi.python.org/pypi/cachier
|
@@ -0,0 +1,176 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = [
|
3
|
+
"setuptools",
|
4
|
+
"wheel",
|
5
|
+
]
|
6
|
+
|
7
|
+
[project]
|
8
|
+
name = "cachier"
|
9
|
+
description = "Persistent, stale-free, local and cross-machine caching for Python functions."
|
10
|
+
readme = "README.rst"
|
11
|
+
keywords = [
|
12
|
+
"cache",
|
13
|
+
"caching",
|
14
|
+
"cross-machine",
|
15
|
+
"decorator",
|
16
|
+
"local",
|
17
|
+
"memoization",
|
18
|
+
"mongo",
|
19
|
+
"persistent",
|
20
|
+
]
|
21
|
+
license = { file = "LICENSE" }
|
22
|
+
authors = [
|
23
|
+
{ name = "Shay Palachy Affek", email = 'shay.palachy@gmail.com' },
|
24
|
+
]
|
25
|
+
classifiers = [
|
26
|
+
"Development Status :: 4 - Beta",
|
27
|
+
"Intended Audience :: Developers",
|
28
|
+
"License :: OSI Approved :: MIT License",
|
29
|
+
"Programming Language :: Python",
|
30
|
+
"Programming Language :: Python :: 3 :: Only",
|
31
|
+
"Programming Language :: Python :: 3.8",
|
32
|
+
"Programming Language :: Python :: 3.9",
|
33
|
+
"Programming Language :: Python :: 3.10",
|
34
|
+
"Programming Language :: Python :: 3.11",
|
35
|
+
"Programming Language :: Python :: 3.12",
|
36
|
+
"Topic :: Other/Nonlisted Topic",
|
37
|
+
"Topic :: Software Development :: Libraries",
|
38
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
39
|
+
"Topic :: Utilities",
|
40
|
+
]
|
41
|
+
dynamic = [
|
42
|
+
"version",
|
43
|
+
]
|
44
|
+
dependencies = [
|
45
|
+
"portalocker>=2.3.2",
|
46
|
+
"watchdog>=2.3.1",
|
47
|
+
]
|
48
|
+
urls.Source = "https://github.com/python-cachier/cachier"
|
49
|
+
scripts.cachier = "cachier.__main__:cli"
|
50
|
+
|
51
|
+
[tool.setuptools]
|
52
|
+
include-package-data = true
|
53
|
+
|
54
|
+
[tool.setuptools.dynamic]
|
55
|
+
version = { attr = "cachier._version.__version__" }
|
56
|
+
|
57
|
+
[tool.setuptools.packages.find]
|
58
|
+
where = [
|
59
|
+
"src",
|
60
|
+
] # list of folders that contain the packages (["."] by default)
|
61
|
+
include = [
|
62
|
+
"cachier*",
|
63
|
+
] # package names should match these glob patterns (["*"] by default)
|
64
|
+
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
|
65
|
+
|
66
|
+
[tool.ruff]
|
67
|
+
target-version = "py38"
|
68
|
+
line-length = 79
|
69
|
+
# Exclude a variety of commonly ignored directories.
|
70
|
+
exclude = [
|
71
|
+
".eggs",
|
72
|
+
".git",
|
73
|
+
".ruff_cache",
|
74
|
+
"__pypackages__",
|
75
|
+
"_build",
|
76
|
+
"build",
|
77
|
+
"dist",
|
78
|
+
]
|
79
|
+
# Enable Pyflakes `E` and `F` codes by default.
|
80
|
+
lint.select = [
|
81
|
+
"D", # see: https://pypi.org/project/pydocstyle
|
82
|
+
"E",
|
83
|
+
"F", # see: https://pypi.org/project/pyflakes
|
84
|
+
"I", #see: https://pypi.org/project/isort/
|
85
|
+
"RUF100", # alternative to yesqa
|
86
|
+
#"N", # see: https://pypi.org/project/pep8-naming
|
87
|
+
"S", # see: https://pypi.org/project/flake8-bandit
|
88
|
+
"SIM",
|
89
|
+
"W", # see: https://pypi.org/project/pycodestyle
|
90
|
+
]
|
91
|
+
lint.extend-select = [
|
92
|
+
"A", # see: https://pypi.org/project/flake8-builtins
|
93
|
+
"B", # see: https://pypi.org/project/flake8-bugbear
|
94
|
+
"C4", # see: https://pypi.org/project/flake8-comprehensions
|
95
|
+
]
|
96
|
+
lint.ignore = [
|
97
|
+
"C901",
|
98
|
+
"E203",
|
99
|
+
]
|
100
|
+
lint.per-file-ignores."src/**/__init__.py" = [
|
101
|
+
"D104",
|
102
|
+
]
|
103
|
+
lint.per-file-ignores."src/cachier/config.py" = [
|
104
|
+
"D100",
|
105
|
+
]
|
106
|
+
lint.per-file-ignores."tests/**" = [
|
107
|
+
"D100",
|
108
|
+
"D101",
|
109
|
+
"D103",
|
110
|
+
"D104",
|
111
|
+
"D401",
|
112
|
+
"S101",
|
113
|
+
"S105",
|
114
|
+
"S311",
|
115
|
+
"S603",
|
116
|
+
]
|
117
|
+
lint.unfixable = [
|
118
|
+
"F401",
|
119
|
+
]
|
120
|
+
|
121
|
+
#[tool.ruff.pydocstyle]
|
122
|
+
## Use Google-style docstrings.
|
123
|
+
#convention = "google"
|
124
|
+
#[tool.ruff.pycodestyle]
|
125
|
+
#ignore-overlong-task-comments = true
|
126
|
+
# Unlike Flake8, default to a complexity level of 10.
|
127
|
+
lint.mccabe.max-complexity = 10
|
128
|
+
|
129
|
+
[tool.docformatter]
|
130
|
+
recursive = true
|
131
|
+
# some docstring start with r"""
|
132
|
+
wrap-summaries = 79
|
133
|
+
wrap-descriptions = 79
|
134
|
+
blank = true
|
135
|
+
|
136
|
+
[tool.pytest.ini_options]
|
137
|
+
testpaths = [
|
138
|
+
"cachier",
|
139
|
+
"tests",
|
140
|
+
]
|
141
|
+
norecursedirs = [
|
142
|
+
"dist",
|
143
|
+
"build",
|
144
|
+
]
|
145
|
+
addopts = [
|
146
|
+
"--color=yes",
|
147
|
+
"--cov=cachier",
|
148
|
+
"--cov-report=term",
|
149
|
+
"--cov-report=xml:cov.xml",
|
150
|
+
"-r a",
|
151
|
+
"-v",
|
152
|
+
"-s",
|
153
|
+
]
|
154
|
+
markers = [
|
155
|
+
"mongo: test the MongoDB core",
|
156
|
+
"memory: test the memory core",
|
157
|
+
"pickle: test the pickle core",
|
158
|
+
]
|
159
|
+
|
160
|
+
[tool.coverage.run]
|
161
|
+
branch = true
|
162
|
+
dynamic_context = "test_function"
|
163
|
+
omit = [
|
164
|
+
"tests/*",
|
165
|
+
"cachier/_version.py",
|
166
|
+
"cachier/__init__.py",
|
167
|
+
"**/scripts/**",
|
168
|
+
]
|
169
|
+
[tool.coverage.report]
|
170
|
+
show_missing = true
|
171
|
+
# Regexes for lines to exclude from consideration
|
172
|
+
exclude_lines = [
|
173
|
+
"pragma: no cover", # Have to re-enable the standard pragma
|
174
|
+
"raise NotImplementedError", # Don't complain if tests don't hit defensive assertion code:
|
175
|
+
"if TYPE_CHECKING:", # Is only true when running mypy, not tests
|
176
|
+
]
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import datetime
|
2
|
+
import hashlib
|
3
|
+
import os
|
4
|
+
import pickle
|
5
|
+
from typing import Optional, TypedDict, Union
|
6
|
+
|
7
|
+
from ._types import Backend, HashFunc, Mongetter
|
8
|
+
|
9
|
+
|
10
|
+
def _default_hash_func(args, kwds):
|
11
|
+
# Sort the kwargs to ensure consistent ordering
|
12
|
+
sorted_kwargs = sorted(kwds.items())
|
13
|
+
# Serialize args and sorted_kwargs using pickle or similar
|
14
|
+
serialized = pickle.dumps((args, sorted_kwargs))
|
15
|
+
# Create a hash of the serialized data
|
16
|
+
return hashlib.sha256(serialized).hexdigest()
|
17
|
+
|
18
|
+
|
19
|
+
class Params(TypedDict):
|
20
|
+
"""Type definition for cachier parameters."""
|
21
|
+
|
22
|
+
caching_enabled: bool
|
23
|
+
hash_func: HashFunc
|
24
|
+
backend: Backend
|
25
|
+
mongetter: Optional[Mongetter]
|
26
|
+
stale_after: datetime.timedelta
|
27
|
+
next_time: bool
|
28
|
+
cache_dir: Union[str, os.PathLike]
|
29
|
+
pickle_reload: bool
|
30
|
+
separate_files: bool
|
31
|
+
wait_for_calc_timeout: int
|
32
|
+
allow_none: bool
|
33
|
+
|
34
|
+
|
35
|
+
_default_params: Params = {
|
36
|
+
"caching_enabled": True,
|
37
|
+
"hash_func": _default_hash_func,
|
38
|
+
"backend": "pickle",
|
39
|
+
"mongetter": None,
|
40
|
+
"stale_after": datetime.timedelta.max,
|
41
|
+
"next_time": False,
|
42
|
+
"cache_dir": "~/.cachier/",
|
43
|
+
"pickle_reload": True,
|
44
|
+
"separate_files": False,
|
45
|
+
"wait_for_calc_timeout": 0,
|
46
|
+
"allow_none": False,
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
def _update_with_defaults(
|
51
|
+
param, name: str, func_kwargs: Optional[dict] = None
|
52
|
+
):
|
53
|
+
import cachier
|
54
|
+
|
55
|
+
if func_kwargs:
|
56
|
+
kw_name = f"cachier__{name}"
|
57
|
+
if kw_name in func_kwargs:
|
58
|
+
return func_kwargs.pop(kw_name)
|
59
|
+
if param is None:
|
60
|
+
return cachier.config._default_params[name]
|
61
|
+
return param
|
62
|
+
|
63
|
+
|
64
|
+
def set_default_params(**params):
|
65
|
+
"""Configure global parameters applicable to all memoized functions.
|
66
|
+
|
67
|
+
This function takes the same keyword parameters as the ones defined in the
|
68
|
+
decorator, which can be passed all at once or with multiple calls.
|
69
|
+
Parameters given directly to a decorator take precedence over any values
|
70
|
+
set by this function.
|
71
|
+
|
72
|
+
Only 'stale_after', 'next_time', and 'wait_for_calc_timeout' can be changed
|
73
|
+
after the memoization decorator has been applied. Other parameters will
|
74
|
+
only have an effect on decorators applied after this function is run.
|
75
|
+
|
76
|
+
"""
|
77
|
+
import cachier
|
78
|
+
|
79
|
+
valid_params = (
|
80
|
+
p for p in params.items() if p[0] in cachier.config._default_params
|
81
|
+
)
|
82
|
+
_default_params.update(valid_params)
|
83
|
+
|
84
|
+
|
85
|
+
def get_default_params():
|
86
|
+
"""Get current set of default parameters."""
|
87
|
+
import cachier
|
88
|
+
|
89
|
+
return cachier.config._default_params
|
90
|
+
|
91
|
+
|
92
|
+
def enable_caching():
|
93
|
+
"""Enable caching globally."""
|
94
|
+
import cachier
|
95
|
+
|
96
|
+
cachier.config._default_params["caching_enabled"] = True
|
97
|
+
|
98
|
+
|
99
|
+
def disable_caching():
|
100
|
+
"""Disable caching globally."""
|
101
|
+
import cachier
|
102
|
+
|
103
|
+
cachier.config._default_params["caching_enabled"] = False
|