Commit 12a73d3
committed
Remove CacheMap#containsKey before #get
Currently, when accessing values from the `DataLoader`'s `CacheMap`, we
first check `#containsKey` before invoking `#get`. This is problematic
for two reasons:
- the underlying cache's metrics are skewed (it will have a 100% hit
rate).
- if the cache has an automatic expiration policy, it is possible a
value will expire between the `containsKey` and `get` invocations
leading to an incorrect result.
To ameliorate this, we always invoke `#get` and check if it is `null` to
deterine whether the key is present. We wrap the invocation in a
`try`/`catch` as the `#get` method is allowed to through per its
documentation.1 parent bd101a2 commit 12a73d3
File tree
2 files changed
+16
-9
lines changed- src/main/java/org/dataloader
2 files changed
+16
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
69 | | - | |
| 68 | + | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
116 | 120 | | |
117 | 121 | | |
118 | 122 | | |
| |||
307 | 311 | | |
308 | 312 | | |
309 | 313 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
314 | 322 | | |
315 | 323 | | |
316 | 324 | | |
| |||
0 commit comments