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

chore(feat): Integrate HTTP Caching Model for authx ✨ #217

Merged
merged 11 commits into from
Mar 20, 2022
Merged

Conversation

yezz123
Copy link
Owner

@yezz123 yezz123 commented Mar 20, 2022

HTTPCache

Overview

HTTP caching occurs when the browser stores local copies of web resources for faster retrieval the next time the resource is required. As your application serves resources it can attach cache headers to the response specifying the desired cache behavior.

Overview

When an item is fully cached, the browser may choose to not contact the server at all and simply use its cached copy:

Overview

HTTP cache headers

There are two primary cache headers, Cache-Control and Expires.

Cache-Control

The Cache-Control header is the most important header to set as it effectively switches on caching in the browser. With this header in place, and set with a value that enables caching, the browser will cache the file for as long as specified. Without this header, the browser will re-request the file on each subsequent request.

Expires

When accompanying the Cache-Control header, Expires simply sets a date from which the cached resource should no longer be considered valid. From this date forward the browser will request a fresh copy of the resource.

This Introduction to HTTP Caching is based on the HTTP Caching Guide.

AuthX provides a simple HTTP caching model designed to work with FastAPI,

Initialize the cache

from authx import HTTPCache
from pytz import timezone

africa_Casablanca = timezone('Africa/Casablanca')
HTTPCache.init(redis_url=REDIS_URL, namespace='test_namespace', tz=africa_Casablanca)

@yezz123 yezz123 added documentation Improvements or additions to documentation enhancement New feature or request dependencies Pull requests that update a dependency file python Pull requests that update Python code labels Mar 20, 2022
@yezz123 yezz123 self-assigned this Mar 20, 2022
Repository owner deleted a comment from pull-request-quantifier-deprecated bot Mar 20, 2022
@codecov
Copy link

codecov bot commented Mar 20, 2022

Codecov Report

Merging #217 (ae940e5) into main (6fa1ef8) will increase coverage by 0.24%.
The diff coverage is 83.86%.

@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
+ Coverage   93.83%   94.07%   +0.24%     
==========================================
  Files          41       46       +5     
  Lines        1444     1706     +262     
==========================================
+ Hits         1355     1605     +250     
- Misses         89      101      +12     
Impacted Files Coverage Δ
tests/utils.py 95.00% <ø> (+16.91%) ⬆️
authx/core/time.py 46.47% <46.47%> (ø)
authx/core/expiry.py 75.86% <75.86%> (ø)
authx/middleware/service.py 86.79% <86.79%> (ø)
tests/cache/test_method_cache.py 92.50% <92.50%> (ø)
authx/models/cache.py 94.73% <94.73%> (ø)
authx/__init__.py 100.00% <100.00%> (ø)
tests/cache/test_cache_config.py 94.11% <100.00%> (-5.89%) ⬇️
tests/cache/test_http_cache.py 100.00% <100.00%> (ø)
tests/cache/test_keys.py 100.00% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fa1ef8...ae940e5. Read the comment docs.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 20, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.13%.

Quality metrics Before After Change
Complexity 0.80 ⭐ 0.80 ⭐ 0.00
Method Length 23.65 ⭐ 24.24 ⭐ 0.59 👎
Working memory 5.37 ⭐ 5.41 ⭐ 0.04 👎
Quality 89.17% 89.04% -0.13% 👎
Other metrics Before After Change
Lines 339 344 5
Changed files Quality Before Quality After Quality Change
authx/init.py 93.90% ⭐ 92.94% ⭐ -0.96% 👎
tests/utils.py 89.56% ⭐ 89.56% ⭐ 0.00%
tests/cache/test_cache_config.py 83.74% ⭐ 82.07% ⭐ -1.67% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
tests/utils.py MockAuthBackend._create_token 3 ⭐ 69 🙂 10 😞 70.52% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@yezz123 yezz123 merged commit a268d60 into main Mar 20, 2022
@yezz123 yezz123 deleted the feat/HTTPCache branch March 20, 2022 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request Extra Large python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant