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

tweak default cache lengths by category #10919

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

chris48s
Copy link
Member

@chris48s chris48s commented Mar 2, 2025

Quick refresher on how we set max-age:

  • Individual badge classes can set a _cacheLength specific to that service
  • If the badge class itself doesn't define a _cacheLength we fall back and use the default for that category. This is the code I am changing in this PR
  • If there is no default set for the category, we fall back and use defaultCacheLengthSeconds (which we set to 120 seconds in production)

The basic principles of setting defaults by category are:

  • There are some data points that need change more frequently than others. Whether your build is passing or failing might change quite frequently. You rarely change your project's license.
  • There are some badges that show quite a precise value (build status, version number), whereas others show a more indicative metric (number of downloads/stars/likes). These are usually rounded with metric(). It is less crucial for an indicative metric to be fresh.

In this PR I am suggesting we tweak the category defaults a bit and add some categories that were previously using the global default of 2 mins. The broad result of all of this being: Cache more things for longer. I am focussing on categories that make up a large proportion of our traffic.

We can always continue to tweak these thresholds.

Also:

  • This doesn't change any situations where we've set a _cacheLength on individual badge classes - those continue to override the defaults by category
  • If there are specific badges where we want to set a shorter length than the category default then we can

@chris48s chris48s added the core Server, BaseService, GitHub auth, Shared helpers label Mar 2, 2025
Copy link
Contributor

github-actions bot commented Mar 2, 2025

Messages
📖 ✨ Thanks for your contribution to Shields, @chris48s!

Generated by 🚫 dangerJS against 50b194f

Comment on lines +155 to +157
'platform-support': 300,
size: 300,
version: 300,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My logic here is that the cadence with which platform support and size change is probably about once per release, so lets treat them the same as version numbers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that platform-support tend to change less then version and size, as most versions would not change supported platform or change major version, but its an improvement from 120s so we might just start with that.

Comment on lines +159 to +162
chat: 1800,
downloads: 1800,
rating: 1800,
social: 1800,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these categories primarily show what I've described as "indicative metrics"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30min seems fair.

Copy link
Member

@jNullj jNullj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, hope this reduces resource use with minimal effect on client usage perception

@chris48s chris48s added this pull request to the merge queue Mar 6, 2025
Merged via the queue into badges:master with commit 5fb5a30 Mar 6, 2025
24 checks passed
@chris48s chris48s deleted the cache-categories202503 branch March 6, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Server, BaseService, GitHub auth, Shared helpers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants