Skip to content

Conversation

@JoeARO
Copy link

@JoeARO JoeARO commented Jun 5, 2025

When upgrading from Cachex 3.6 to 4.1 we noticed the behaviour of the pruning had changed compared to our own loose implementation of LRU on top of Cachex 3.6.
After some investigation we found that the default value for the pruning was not as defined in the documentation. This PR sets the default back to 1000ms (1 Second).
Once we updated the frequency via the Scheduled Hook options the behaviour returned to what we expected.

If the preference is to keep the default frequency at 3 seconds, then feel free to bin this PR. But it is worth noting the documentation and the migration guide would need to be updated to reflect the behaviour.

Additionaly improve clarity of set value using a module attribute
@JoeARO JoeARO changed the title Set default frequency to 1000ms Set default frequency to 1000ms for Cachex.Limit.Scheduled Jun 5, 2025
@whitfin
Copy link
Owner

whitfin commented Jun 6, 2025

Hi @JoeARO!

You're right that this changed in the 4.0 release, and you're right it wasn't documented. As far as I know there was no hard contract documented on the interval, because it's not a guaranteed interval anyway. As such I'm probably not going to merge this back in. I think a few seconds is a saner default.

Having said that I notice that this thread has several upvotes already, so I'm wondering if this is somehow a bigger issue than I think? @isavita @GuiHeurich @tracy-o do you have anything to add here?

@isavita
Copy link
Contributor

isavita commented Jun 6, 2025

@whitfin It is okay to stay 3s, we fixed it in our codebase anway, but probably fixing this https://github.com/whitfin/cachex/blob/main/lib/cachex/limit/scheduled.ex#L24. Done here #415

@JoeARO
Copy link
Author

JoeARO commented Jun 6, 2025

@whitfin thanks for getting back to me, I'll close this in favour of @isavita's PR #415.

For us a lower frequency is much better due to the size and amount of items in the cache so its nice we can configure it, was just a bit of a shock when we hadn't spotted it was 3 seconds and thought we may not be able to upgrade Cachex, until I found the :time.seconds(3).
I wonder for a minor change if the module attribute for clearer naming and keeping it to the style in the docs by setting it as 3_000 directly might be good over the :timer. Just a thought though 🙂

Also @isavita @GuiHeurich @tracy-o are my colleagues, I had just shared the PR to keep them in the loop!

@JoeARO JoeARO closed this Jun 6, 2025
@whitfin
Copy link
Owner

whitfin commented Jun 6, 2025

@JoeARO @isavita ah okay, got it! The reasoning is that most people don't need it to be cleaned up as frequently, so we can do it 1/3 as often without any noticeable impact. Given that it's configurable, I think it's probably fine -- but for anyone who ends up here later, I'm open to changing the default based on feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants