Skip to content

0.4.0 - HTTPCache

Choose a tag to compare

@yezz123 yezz123 released this 20 Mar 16:31
· 1195 commits to main since this release
fac32a5

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)

What's Changed

  • chore(docs): Improve Documentation by @yezz123 in #209
  • chore(dev): refactor code & improve some exceptions ✨ by @yezz123 in #212
  • ref: Use the built-in function next instead of a for-loop. by @yezz123 in #213
  • chore(docs): add New Sponsors ✨❤️ by @yezz123 in #214
  • docs(mkdocs.yml): Change name from middlewares to middleware by @theoohoho in #215
  • chore(f/l): Integrate Pyupgrade to AuthX Environment by @yezz123 in #216
  • chore(feat): Integrate HTTP Caching Model for authx ✨ by @yezz123 in #217
  • docs: add theoohoho as a contributor for doc by @allcontributors in #218
  • chore(Example): Provide New Cache Example✨ by @yezz123 in #219

New Contributors

Full Changelog: 0.3.1...0.4.0