Skip to content

Commit

Permalink
RegexMatchCache::hasItemsToPurge
Browse files Browse the repository at this point in the history
Summary:
A `const` check for whether `RegexMatchCache::purge`, which is non-`cont`, would have any work to do.

For concurrent access, `hasItemsToPurge` can be invoked with a shared lock held and, only if it returns `true`, would `purge` be invoked with an exclusive lock held.

Reviewed By: Gownta

Differential Revision: D66730362

fbshipit-source-id: 678872260faff868671c76875408f4357511b58b
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Dec 4, 2024
1 parent 935b5d0 commit 81a2550
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions folly/container/RegexMatchCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,16 @@ std::vector<RegexMatchCache::string_pointer> RegexMatchCache::findMatches(
return {matches.begin(), matches.end()};
}

bool RegexMatchCache::hasItemsToPurge(time_point const expiry) const noexcept {
for (auto const& [regex, entry] : cacheRegexToMatch_) {
auto const accessed_at = entry.accessed_at.load(std::memory_order_relaxed);
if (accessed_at <= expiry) {
return true;
}
}
return false;
}

void RegexMatchCache::clear() {
std::exchange(stringQueueReverse_, {});
std::exchange(stringQueueForward_, {});
Expand Down
2 changes: 2 additions & 0 deletions folly/container/RegexMatchCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ class RegexMatchCache {
std::vector<string_pointer> findMatches(
regex_key const& regex, time_point now) const;

bool hasItemsToPurge(time_point expiry) const noexcept;

void clear();
void purge(time_point expiry);
};
Expand Down

0 comments on commit 81a2550

Please sign in to comment.