@@ -26,7 +26,6 @@ class CachingAlgorithmFlag(enum.IntFlag):
2626 FIFO = 1 # First In First Out
2727 LRU = 2 # Least Recently Used
2828 LFU = 4 # Least Frequently Used
29-
3029```
3130
3231By default, these three internal algorithms are registered.
@@ -48,7 +47,7 @@ def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe):
4847Note that you should also attach several members to the created wrapper,
4948so that users can do some operations.
5049
51- This two functions are * required* :
50+ These two functions are * required* :
5251
5352``` python
5453# To see the statistics information
@@ -58,17 +57,42 @@ wrapper.cache_info()
5857wrapper.cache_clear()
5958```
6059
61- For testing purposes, this two members are * optional* , but recommended:
60+ These nine functions are * optional* , but recommended:
61+
62+ ``` python
63+ # To see whether the cache is empty
64+ wrapper.cache_is_empty()
65+
66+ # To see whether the cache is full
67+ wrapper.cache_is_full()
68+
69+ # To see whether the cache contains a cached item with the specified function call arguments
70+ wrapper.cache_contains_argument(function_arguments, alive_only)
71+
72+ # To see whether the cache contains a cache item with the specified user function return value
73+ wrapper.cache_contains_result(return_value, alive_only)
74+
75+ # To perform the given action for each cache element
76+ wrapper.cache_for_each(consumer)
77+
78+ # To get user function arguments of all alive cache elements
79+ wrapper.cache_arguments()
80+
81+ # To get user function return values of all alive cache elements
82+ wrapper.cache_results()
83+
84+ # To get cache items, i.e. entries of all alive cache elements, in the form of (argument, result)
85+ wrapper.cache_items()
86+
87+ # To remove all cache elements that satisfy the given predicate
88+ wrapper.cache_remove_if(predicate)
89+ ```
90+
91+ For testing purposes, this member is * optional* , but recommended:
6292``` python
6393# Access to the cache which is typically a hash map with function
6494# arguments as its key and function return values as its value
6595wrapper._cache
66-
67- # Get an ordered list which represents the internal caching orders,
68- # from the most important key-value entry (aka the least possible one
69- # to be evicted from cache) to the least important one (aka the most
70- # possible one to be evicted)
71- wrapper._get_caching_list()
7296```
7397
7498Please refer to ` fifo_cache.py ` as an example. Your code should looks like:
@@ -102,7 +126,6 @@ def get_caching_wrapper(user_function, max_size, ttl, algorithm, thread_safe):
102126 wrapper.cache_clear = cache_clear
103127 wrapper.cache_info = cache_info
104128 wrapper._cache = ...
105- wrapper._get_caching_list = ...
106129
107130 return wrapper
108131
@@ -156,4 +179,4 @@ your code pass them before you submit a pull request.
156179
157180## Acknowledgements
158181
159- Thank you again, developer, for helping me improve this project.
182+ Thank you again, developer, for helping us improve this project.
0 commit comments