Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

safety: rework cache cleanup logic #1753

Merged
merged 2 commits into from
Dec 2, 2019
Merged

safety: rework cache cleanup logic #1753

merged 2 commits into from
Dec 2, 2019

Conversation

dgw
Copy link
Member

@dgw dgw commented Nov 16, 2019

Details in the commit message, but the gist is implementing exactly what I described previously. This resolves #1572, assuming I haven't made any silly mistakes.

First of all, the old cleanup function was comparing timestamps the
wrong way round, so it would end up deleting the NEWEST key.

Second, it would only ever delete one cache key, regardless of how many
entries over the limit the cache was.

Now, we have an initial age-based cleanup that deletes all cache entries
older than 7 days. If the cache is still over 512 entries, the oldest n
entries are removed, where n is (cache_size - cache_limit).

The daily cleanup schedule is still used. The cache cleanup now targets
512 entries instead of 1024, but a "cache too large" cleanup will still
trigger only if the cache reaches 1024 items (twice the target size) to
keep from triggering the relatively more expensive cleanup function for
minor removals of just one or two entries.

There is also now a lock to prevent running more than one simultaneous
cleanup function call.
@dgw dgw added Medium Priority Bugfix Generally, PRs that reference (and fix) one or more issue(s) labels Nov 16, 2019
@dgw dgw added this to the 7.0.0 milestone Nov 16, 2019
@dgw dgw requested a review from a team November 16, 2019 20:11
sopel/modules/safety.py Outdated Show resolved Hide resolved
@dgw dgw requested a review from Exirel November 24, 2019 07:41
@dgw dgw merged commit 0bf8c5a into master Dec 2, 2019
@dgw dgw deleted the safety-cache branch December 2, 2019 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Generally, PRs that reference (and fix) one or more issue(s) Medium Priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

safety: _clean_cache() doesn't, not really
2 participants