Skip to content

Commit d19e6cf

Browse files
committed
Minor cleanup
1 parent 4064858 commit d19e6cf

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pySDC/helpers/spectral_helper.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,34 @@
66
import logging
77

88
# TODO: implement cupy for transforms
9-
# TODO: fix edge cases
109

1110

1211
def cache(func):
12+
"""
13+
Decorator for caching return values of functions.
14+
15+
Example:
16+
17+
.. code-block:: python
18+
19+
num_calls = 0
20+
21+
@cache
22+
def increment(x):
23+
num_calls += 1
24+
return x + 1
25+
26+
increment(0) # returns 1, num_calls = 1
27+
increment(1) # returns 2, num_calls = 2
28+
increment(0) # returns 1, num_calls = 2
29+
30+
31+
Args:
32+
func (function): The function you want to cache the return value of
33+
34+
Returns:
35+
return value of func
36+
"""
1337
attr_cache = f"_{func.__name__}_cache"
1438

1539
@wraps(func)

0 commit comments

Comments
 (0)