Skip to content

Commit 71862e2

Browse files
committed
update api fucntion docs
1 parent 9cdfba9 commit 71862e2

File tree

6 files changed

+174
-62
lines changed

6 files changed

+174
-62
lines changed

memoization/caching/fifo_cache.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99

1010
def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, order_independent, custom_key_maker):
11-
"""
12-
Get a caching wrapper for FIFO cache
13-
"""
11+
"""Get a caching wrapper for FIFO cache"""
1412

1513
cache = {} # the cache to store function results
1614
key_argument_map = {} # mapping from cache keys to user function arguments
@@ -39,9 +37,7 @@ def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, or
3937
_VALUE = 3 # index for the value
4038

4139
def wrapper(*args, **kwargs):
42-
"""
43-
The actual wrapper
44-
"""
40+
"""The actual wrapper"""
4541
nonlocal hits, misses, root, full
4642
key = make_key(args, kwargs)
4743
cache_expired = False
@@ -93,9 +89,7 @@ def wrapper(*args, **kwargs):
9389
return result
9490

9591
def cache_clear():
96-
"""
97-
Clear the cache and its statistics information
98-
"""
92+
"""Clear the cache and its statistics information"""
9993
nonlocal hits, misses, full
10094
with lock:
10195
cache.clear()
@@ -107,6 +101,7 @@ def cache_clear():
107101
def cache_info():
108102
"""
109103
Show statistics information
104+
110105
:return: a CacheInfo object describing the cache
111106
"""
112107
with lock:
@@ -190,7 +185,7 @@ def cache_contains_result(return_value, alive_only=True):
190185

191186
def cache_for_each(consumer):
192187
"""
193-
Perform the given action for each cache element in an order determined by the algorithm (FIFO) until all
188+
Perform the given action for each cache element in an order determined by the algorithm until all
194189
elements have been processed or the action throws an error
195190
196191
:param consumer: an action function to process the cache elements. Must have 3 arguments:

memoization/caching/lfu_cache.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99

1010
def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, order_independent, custom_key_maker):
11-
"""
12-
Get a caching wrapper for LFU cache
13-
"""
11+
"""Get a caching wrapper for LFU cache"""
1412

1513
cache = {} # the cache to store function results
1614
key_argument_map = {} # mapping from cache keys to user function arguments
@@ -31,9 +29,7 @@ def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, or
3129
lfu_freq_list_root = _FreqNode.root() # LFU frequency list root
3230

3331
def wrapper(*args, **kwargs):
34-
"""
35-
The actual wrapper
36-
"""
32+
"""The actual wrapper"""
3733
nonlocal hits, misses
3834
key = make_key(args, kwargs)
3935
cache_expired = False
@@ -64,9 +60,7 @@ def wrapper(*args, **kwargs):
6460
return result
6561

6662
def cache_clear():
67-
"""
68-
Clear the cache and its statistics information
69-
"""
63+
"""Clear the cache and its statistics information"""
7064
nonlocal hits, misses, lfu_freq_list_root
7165
with lock:
7266
cache.clear()
@@ -77,6 +71,7 @@ def cache_clear():
7771
def cache_info():
7872
"""
7973
Show statistics information
74+
8075
:return: a CacheInfo object describing the cache
8176
"""
8277
with lock:
@@ -164,7 +159,7 @@ def cache_contains_result(return_value, alive_only=True):
164159

165160
def cache_for_each(consumer):
166161
"""
167-
Perform the given action for each cache element in an order determined by the algorithm (FIFO) until all
162+
Perform the given action for each cache element in an order determined by the algorithm until all
168163
elements have been processed or the action throws an error
169164
170165
:param consumer: an action function to process the cache elements. Must have 3 arguments:

memoization/caching/lru_cache.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99

1010
def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, order_independent, custom_key_maker):
11-
"""
12-
Get a caching wrapper for LRU cache
13-
"""
11+
"""Get a caching wrapper for LRU cache"""
1412

1513
cache = {} # the cache to store function results
1614
key_argument_map = {} # mapping from cache keys to user function arguments
@@ -39,9 +37,7 @@ def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, or
3937
_VALUE = 3 # index for the value
4038

4139
def wrapper(*args, **kwargs):
42-
"""
43-
The actual wrapper
44-
"""
40+
"""The actual wrapper"""
4541
nonlocal hits, misses, root, full
4642
key = make_key(args, kwargs)
4743
cache_expired = False
@@ -102,9 +98,7 @@ def wrapper(*args, **kwargs):
10298
return result
10399

104100
def cache_clear():
105-
"""
106-
Clear the cache and its statistics information
107-
"""
101+
"""Clear the cache and its statistics information"""
108102
nonlocal hits, misses, full
109103
with lock:
110104
cache.clear()
@@ -116,6 +110,7 @@ def cache_clear():
116110
def cache_info():
117111
"""
118112
Show statistics information
113+
119114
:return: a CacheInfo object describing the cache
120115
"""
121116
with lock:
@@ -199,7 +194,7 @@ def cache_contains_result(return_value, alive_only=True):
199194

200195
def cache_for_each(consumer):
201196
"""
202-
Perform the given action for each cache element in an order determined by the algorithm (FIFO) until all
197+
Perform the given action for each cache element in an order determined by the algorithm until all
203198
elements have been processed or the action throws an error
204199
205200
:param consumer: an action function to process the cache elements. Must have 3 arguments:

memoization/caching/plain_cache.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99

1010
def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, order_independent, custom_key_maker):
11-
"""
12-
Get a caching wrapper for space-unlimited cache
13-
"""
11+
"""Get a caching wrapper for space-unlimited cache"""
1412

1513
cache = {} # the cache to store function results
1614
key_argument_map = {} # mapping from cache keys to user function arguments
@@ -30,9 +28,7 @@ def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, or
3028
make_key = keys_toolkit_order_dependent.make_key
3129

3230
def wrapper(*args, **kwargs):
33-
"""
34-
The actual wrapper
35-
"""
31+
"""The actual wrapper"""
3632
nonlocal hits, misses
3733
key = make_key(args, kwargs)
3834
value = cache.get(key, sentinel)
@@ -49,9 +45,7 @@ def wrapper(*args, **kwargs):
4945
return result
5046

5147
def cache_clear():
52-
"""
53-
Clear the cache and statistics information
54-
"""
48+
"""Clear the cache and statistics information"""
5549
nonlocal hits, misses
5650
with lock:
5751
cache.clear()
@@ -61,6 +55,7 @@ def cache_clear():
6155
def cache_info():
6256
"""
6357
Show statistics information
58+
6459
:return: a CacheInfo object describing the cache
6560
"""
6661
with lock:
@@ -142,7 +137,7 @@ def cache_contains_result(return_value, alive_only=True):
142137

143138
def cache_for_each(consumer):
144139
"""
145-
Perform the given action for each cache element in an order determined by the algorithm (FIFO) until all
140+
Perform the given action for each cache element in an order determined by the algorithm until all
146141
elements have been processed or the action throws an error
147142
148143
:param consumer: an action function to process the cache elements. Must have 3 arguments:

memoization/caching/statistic_cache.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,28 @@
44

55

66
def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe, order_independent, custom_key_maker):
7-
"""
8-
Get a caching wrapper for statistics only, without any actual caching
9-
"""
7+
"""Get a caching wrapper for statistics only, without any actual caching"""
108

119
misses = 0 # number of misses of the cache
1210
lock = RLock() if thread_safe else DummyWithable() # ensure thread-safe
1311

1412
def wrapper(*args, **kwargs):
15-
"""
16-
The actual wrapper
17-
"""
13+
"""The actual wrapper"""
1814
nonlocal misses
1915
with lock:
2016
misses += 1
2117
return user_function(*args, **kwargs)
2218

2319
def cache_clear():
24-
"""
25-
Clear the cache and statistics information
26-
"""
20+
"""Clear the cache and statistics information"""
2721
nonlocal misses
2822
with lock:
2923
misses = 0
3024

3125
def cache_info():
3226
"""
3327
Show statistics information
28+
3429
:return: a CacheInfo object describing the cache
3530
"""
3631
with lock:
@@ -88,7 +83,7 @@ def cache_contains_result(return_value, alive_only=True):
8883

8984
def cache_for_each(consumer):
9085
"""
91-
Perform the given action for each cache element in an order determined by the algorithm (FIFO) until all
86+
Perform the given action for each cache element in an order determined by the algorithm until all
9287
elements have been processed or the action throws an error
9388
9489
:param consumer: an action function to process the cache elements. Must have 3 arguments:

0 commit comments

Comments
 (0)