-
Notifications
You must be signed in to change notification settings - Fork 23
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
add cache_info
#43
add cache_info
#43
Conversation
BTW, |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #43 +/- ##
==========================================
+ Coverage 77.06% 78.45% +1.39%
==========================================
Files 2 2
Lines 279 297 +18
==========================================
+ Hits 215 233 +18
Misses 64 64 ☔ View full report in Codecov by Sentry. |
I think the case function weird_cache_user(cache, x)
if haskey(cache, x)
return cache[x]
else
cache[x] = f(x)
end
end Here, we are clearly using I think having Therefore, I think having That's really the only design question I had open, and I've managed to convince myself it is right 😅. So then there's the question of "do we want this feature", and from #28 it sounds like the answer to yes. And there's the question "is it implemented correctly", and I checked again and indeed every hit/miss is inside the lock, and every return path of So therefore I think we should reverse the inertia here, and I'll say if there's no objection within a week, I'll merge & tag this. (if there is review before then, much appreciated!). |
I believe this can be merged and the new version can be tagged. Thanks for all this nice work @ericphanson. |
closes #28
I think this should have minimal performance impact, since we simply increment an integer on hits/misses. We are already in the lock in each case, so we don't need to take it.
Some choices:
empty!
, like how functools clears both entries and stats onempty_cache()
.get
andget!
since those are on the only viable methods to use for caching. e.g.setindex!
doesn't care about the existing value so it doesn't make sense to count it as a hit/miss. Andgetindex
errors if the value is not present, so it doesn't really seem like that should count as a cache miss (rather, it is exceptional behavior). This aligns with the README documentation that only describesget
andget!
as fulfilling a caching interface.show
method to functools, since it clearly communicates how to access the entries. I switched the order slightly compared to functools (currentsize
beforemaxsize
because it makes more sense to me).cache_info
provides an immutable snapshot rather than a reference to the cache. This way there isn't a need for locking on access to to the cache info fields.getproperty
overloads for api compatibility. I don't forsee that we would need this though.To check it is correct according to this api, check that every branch of
get
andget!
either increments a hit or a miss, and does so within the lock. (I believe I've done so).