You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2.```lru_cache``` is vulnerable to [__hash collision attack__](https://learncryptography.com/hash-functions/hash-collision-attack)
52
-
and can be hacked or compromised. Using this technique, attackers can make your program unexpectedly slow by feeding
53
-
the cached function with certain cleverly designed inputs. However, in ```memoization```, caching is always typed,
54
-
which means ```f(3)``` and ```f(3.0)``` will be treated as different calls and cached separately. Also, you can
55
-
build your own cache key with a unique hashing strategy. These measures prevents the attack from happening
56
-
(or at least makes it a lot harder).
52
+
and can be hacked or compromised. Using this technique, attackers can make your program __unexpectedly slow__ by
53
+
feeding the cached function with certain cleverly designed inputs. However, in ```memoization```, caching is always
54
+
typed, which means ```f(3)``` and ```f(3.0)``` will be treated as different calls and cached separately. Also,
55
+
you can build your own cache key with a unique hashing strategy. These measures __prevents the attack__ from
56
+
happening (or at least makes it a lot harder).
57
57
58
58
```python
59
59
>>>hash((1,))
@@ -86,7 +86,7 @@ def func(arg):
86
86
Simple enough - the results of ```func()``` are cached.
87
87
Repetitive calls to ```func()``` with the same arguments run ```func()``` only once, enhancing performance.
88
88
89
-
>:warning:__WARNING:__ for functions with unhashable arguments, the default setting may not enable `memoization` to work properly. [Details](https://github.com/lonelyenvoy/python-memoization#custom-cache-keys)
89
+
>:warning:__WARNING:__ for functions with unhashable arguments, the default setting may not enable `memoization` to work properly. See [custom cache keys](https://github.com/lonelyenvoy/python-memoization#custom-cache-keys) section below for details.
90
90
91
91
## 10-Minute Tutorial
92
92
@@ -165,7 +165,7 @@ def func(**kwargs):
165
165
Prior to memorize your function inputs and outputs (i.e. putting them into a cache), `memoization` needs to
166
166
build a __cache key__ using the inputs, so that the outputs can be retrieved later.
167
167
168
-
By default, `memoization` tries to combine all your function
168
+
> By default, `memoization` tries to combine all your function
169
169
arguments and calculate its hash value using `hash()`. If it turns out that parts of your arguments are
170
170
unhashable, `memoization` will fall back to turning them into a string using `str()`. This behavior relies
171
171
on the assumption that the string exactly represents the internal state of the arguments, which is true for
@@ -175,7 +175,7 @@ However, this is not true for all objects. __If you pass objects which are
175
175
instances of non-built-in classes, sometimes you will need to override the default key-making procedure__,
176
176
because the `str()` function on these objects may not hold the correct information about their states.
177
177
178
-
Here are some suggestions. Implementations of a valid key maker:
178
+
Here are some suggestions. __Implementations of a valid key maker__:
179
179
180
180
- MUST be a function with the same signature as the cached function.
181
181
- MUST produce unique keys, which means two sets of different arguments always map to two different keys.
0 commit comments