Skip to content

Commit 926e5f3

Browse files
committed
update readme
1 parent 480ad4b commit 926e5f3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ TypeError: unhashable type: 'list'
4949
```
5050

5151
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).
5757

5858
```python
5959
>>> hash((1,))
@@ -86,7 +86,7 @@ def func(arg):
8686
Simple enough - the results of ```func()``` are cached.
8787
Repetitive calls to ```func()``` with the same arguments run ```func()``` only once, enhancing performance.
8888

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.
9090
9191
## 10-Minute Tutorial
9292

@@ -165,7 +165,7 @@ def func(**kwargs):
165165
Prior to memorize your function inputs and outputs (i.e. putting them into a cache), `memoization` needs to
166166
build a __cache key__ using the inputs, so that the outputs can be retrieved later.
167167

168-
By default, `memoization` tries to combine all your function
168+
> By default, `memoization` tries to combine all your function
169169
arguments and calculate its hash value using `hash()`. If it turns out that parts of your arguments are
170170
unhashable, `memoization` will fall back to turning them into a string using `str()`. This behavior relies
171171
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
175175
instances of non-built-in classes, sometimes you will need to override the default key-making procedure__,
176176
because the `str()` function on these objects may not hold the correct information about their states.
177177

178-
Here are some suggestions. Implementations of a valid key maker:
178+
Here are some suggestions. __Implementations of a valid key maker__:
179179

180180
- MUST be a function with the same signature as the cached function.
181181
- MUST produce unique keys, which means two sets of different arguments always map to two different keys.

0 commit comments

Comments
 (0)