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

Add asyncio.Lock mutex to _request #227

Merged
merged 5 commits into from
Feb 27, 2024
Merged

Conversation

rudcode
Copy link
Contributor

@rudcode rudcode commented Feb 26, 2024

With this change if there is simultaneous request to the same url at the same time, it will only fetch the url once and the rest is feeded from cache

@olk-m @JWCook

I create a test like this, is it enough?

With this change if there is simultaneous request to the same url at the same time, it will only fetch the url once and the rest is feeded from cache
Copy link

codecov bot commented Feb 26, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 97.31%. Comparing base (5b54454) to head (af930dc).
Report is 1 commits behind head on main.

Files Patch % Lines
aiohttp_client_cache/session.py 87.80% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #227      +/-   ##
==========================================
- Coverage   97.75%   97.31%   -0.44%     
==========================================
  Files          10       10              
  Lines        1025     1044      +19     
  Branches      173      177       +4     
==========================================
+ Hits         1002     1016      +14     
- Misses         16       20       +4     
- Partials        7        8       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

aiohttp_client_cache/session.py Outdated Show resolved Hide resolved
@JWCook
Copy link
Member

JWCook commented Feb 26, 2024

Another thing to consider is lock cleanup. For a long-running cache with a large number of unique requests, the number of cache keys in memory could start to add up (roughly 1MB per 6K unique requests). I don't think that needs to be solved in this PR, though. I'll create a separate issue for that (#228).

@JWCook JWCook mentioned this pull request Feb 26, 2024
@rudcode
Copy link
Contributor Author

rudcode commented Feb 26, 2024

Hi @JWCook, I use the lru_cache like you mention in #228, is it okay if I implement like this af930dc? Is 16k enough for the maxsize?

@JWCook @olk-m I use if/else for the python version but I think this makes the build check failed. What do you think?

@JWCook
Copy link
Member

JWCook commented Feb 27, 2024

I use the lru_cache like you mention in #228, is it okay if I implement like this af930dc? Is 16k enough for the maxsize?

Yes, that looks good to me!

I use if/else for the python version but I think this makes the build check failed

That's fine, it looks like that's just because test coverage is only run for python 3.11 right now, so it thinks that else branch (python <=3.9) isn't covered.

@JWCook JWCook added the enhancement New feature or request label Feb 27, 2024
@JWCook JWCook added this to the v0.11 milestone Feb 27, 2024
@JWCook JWCook merged commit ae87dfd into requests-cache:main Feb 27, 2024
6 of 8 checks passed
@JWCook
Copy link
Member

JWCook commented Feb 27, 2024

Merged. Thanks for the contribution @rudcode!

@JWCook JWCook modified the milestones: v0.11, v0.12 Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants