Commit 760f530
committed
docs(core.utils): steer callers away from the racy contains+get idiom
Add a note to ``ProgramCacheResource``'s class docstring telling
callers to use ``cache.get(key)`` (or a try/except around
``cache[key]``) rather than the two-call ``if key in cache: data =
cache[key]`` pattern. The two-call pattern is racy across
processes: another writer's ``os.replace`` or an evictor's
``unlink`` can land between the membership check and the read.
``get`` answers both questions in one filesystem operation, so a
successful return always carries the bytes.
Documents the contract rather than building locks or reservations
to "fix" the race -- the right fix is the recommended idiom.
``__contains__`` stays around for diagnostics and tests.1 parent 4687a17 commit 760f530
1 file changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
138 | 150 | | |
139 | 151 | | |
140 | 152 | | |
| |||
0 commit comments