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

Fix main API & Stats typespecs and provide default values for stats #204

Closed
wants to merge 6 commits into from

Conversation

bryannaegele
Copy link

@bryannaegele bryannaegele commented Dec 27, 2018

The typespecs for stats currently do not match the return values and cause dialyzer errors for users. To update and keep the typespec accurate, default values for the stats properties should be present as this is the most common use case. Specs for all the main API functions not related to distributed or dump/load functionality have been updated to accurately reflect possible return values.

I would advocate for moving hit/miss rates to the gen_server retrieve as I do not see any risk to calculating when retrieving since the divide by zero cases are covered and this would centralize all of the stats. I did not move it at this time but would be happy to as part of this PR.

There are a few small code cleanups, as well.

@bryannaegele bryannaegele changed the title Fix stats typespecs and provide default values Fix main API & Stats typespecs and provide default values for stats Dec 27, 2018
@whitfin
Copy link
Owner

whitfin commented Dec 27, 2018

Hi @bryannaegele! There's a lot going on here, so my preference would be to open PRs specific to each piece so I can merge things in stages. I've separated feedback for the individual parts below:

Typespecs

Although typespec changes are welcomed, there are many missing errors which exist beyond :no_cache. It would be better do make a PR specifically for dialyzer based stuff where we can work solely on that (I don't use dialyzer, so never really worried about it). Although there is improvement in this PR, it's still not accurate.

Statistics

The statistics are deliberately empty as content is dynamic and may or may not be poplated (ever). I'm not sure I understand the point of throwing in a bunch of 0. What's more, it seems quite arbitrary as calls: %{ } does not include defaults for what can go in there either?

I would advocate for moving hit/miss rates to the gen_server retrieve as I do not see any risk to calculating when retrieving since the divide by zero cases are covered and this would centralize all of the stats.

I'm against this because a) there's no real value to doing so, and b) it adds more work to the server process. Don't forget that any work done in the retrieve calls will block registration of cache actions in the meantime.

Cleanup

I don't see much here considered cleanup beyond adding a |> and stats_no_meta. I don't see much point to either of these, so I don't see the need to make these changes.

Summary

Please open a PR (or separate issue) for dialyzer issues, and we can work on making sure every spec is correctly defined (of course, you could also turn this PR into dialyzer specific changes). For statistics, I'm not convinced there needs to be any change there - especially considering it appears to just turn into unnecessary noise.

@bryannaegele
Copy link
Author

Hey @whitfin! If we decide to continue to use Cachex then I can devote more time to get things to a good place for merging back in pieces. For now, I just needed get Dialyzer into a happy space for our builds as we make heavy use of it. If we do determine to adopt beyond an initial spike, would you be able to chat to figure out a plan to tackle the typespecs? We could chat more at that time about stats so I have a better understanding of your concerns.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants