| 135 | } |
| 136 | |
| 137 | bool APICache::needsRefresh() |
| 138 | { |
| 139 | using clock = std::chrono::steady_clock; |
| 140 | if (base) |
| 141 | { |
| 142 | // Update lastRefresh in case base was refreshed |
| 143 | lastRefresh = std::max(lastRefresh, base->lastRefresh); |
| 144 | } |
| 145 | |
| 146 | // Explicitly check for zero in case refreshDuration is duration::max() |
| 147 | // Negative duration causes overflow check to overflow itself |
| 148 | if (lastRefresh.time_since_epoch().count() == 0 || refreshDuration.count() < 0) |
| 149 | { |
| 150 | // No value set yet |
| 151 | return true; |
| 152 | } |
| 153 | // Check if nextRefresh would overflow (assumes lastRefresh is not negative, which it should not be). |
| 154 | // If addition would overflow, do not refresh |
| 155 | else if (clock::duration::max() - refreshDuration > lastRefresh.time_since_epoch()) |
| 156 | { |
| 157 | clock::time_point nextRefresh = lastRefresh + refreshDuration; |
| 158 | if (clock::now() >= nextRefresh) |
| 159 | { |
| 160 | return true; |
| 161 | } |
| 162 | } |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | std::string APICache::getRequestPath() const |
| 167 | { |