Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
full page caching in general and Django
Search
Denis Cornehl
May 19, 2015
Technology
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
full page caching in general and Django
Denis Cornehl
May 19, 2015
More Decks by Denis Cornehl
See All by Denis Cornehl
PDF generation techniques in Python and Django
syphar
0
96
Other Decks in Technology
See All in Technology
JAWSUG TOHOKU 青森支部 「LoGoチャット」のAWS移行で 乗り越えたこと
taketakekaho
0
330
その Valkey 使いこなしていますか?
onk
PRO
5
1.5k
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
130
分析AIエージェントを育てる、動く環境を育てる
codatum
1
1.1k
日本語に強いオープンな大規模言語モデル「LLM-jp」
odashi
4
1.1k
AI駆動開発の時代になったのでトヨタ生産方式から見直す
terurou
7
6k
Refining Active Record
shugo
0
160
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
6
4.9k
DGX Spark でどこまでハッキングができるのか?
kash1064
3
1.3k
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
880
SAENM ~Jupyterで残すPoCの試行錯誤、未来の自分と仲間を助ける記録!~
terapyon
0
110
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
190
Featured
See All Featured
Visualization
eitanlees
153
17k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
550
Building the Perfect Custom Keyboard
takai
2
910
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
930
Six Lessons from altMBA
skipperchong
29
4.5k
Documentation Writing (for coders)
carmenintech
77
5.6k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Unsuck your backbone
ammeep
672
58k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
Transcript
Things Caches Do HTTP / Headers
kinds of web caches • Browser Caches • Proxy Caches
• Gateway Caches
Gateway caches • Varnish on your server • CDN •
„reverse proxy“
expiration • Cache-Control: max-age=N • Expires (for your CDN) •
Surrogate-Control: max-age=N • Cache-Control: s-max-age=N
expiration
expiration
validation • Last-Modified / If-Modified-Since • ETag / If-None-Match •
HTTP Response: 304 Not Modified
validation
validation
cache key
cache key https://api.thermondo.de/settings/
cache key https://api.thermondo.de/settings/ • method (GET) • path (/api/settings/) •
GET arguments (most times) • more?
cache key https://api.thermondo.de/settings/ • method (GET) • path (/api/settings/) •
GET arguments (most times) • Language • Encoding • more?
cache key https://api.thermondo.de/settings/ • method (GET) • path (/api/settings/) •
GET arguments (most times) • Language • Encoding • User Session
vary $ http -h https://api.thermondo.de/settings/ „Authorization: Token secrettoken" HTTP/1.1 200
OK Allow: GET, HEAD, OPTIONS Api-Version: 1.0.0 Connection: keep-alive Content-Encoding: gzip Content-Language: en-us Content-Length: 646 Content-Type: application/json Date: Mon, 30 Mar 2015 12:48:31 GMT Etag: "9987fab5ec7adb7c70be2a24e3665a5b;gzip" Server: waitress Vary: Accept, Accept-Language, Cookie, Accept-Encoding Via: 1.1 vegur
vary $ http -h https://api.thermondo.de/settings/ „Authorization: Token secrettoken" HTTP/1.1 200
OK Allow: GET, HEAD, OPTIONS Api-Version: 1.0.0 Connection: keep-alive Content-Encoding: gzip Content-Language: en-us Content-Length: 646 Content-Type: application/json Date: Mon, 30 Mar 2015 12:48:31 GMT Etag: "9987fab5ec7adb7c70be2a24e3665a5b;gzip" Vary: Accept, Accept-Language, Cookie, Accept-Encoding Via: 1.1 vegur
on cookies
on cookies • session • google analytics • often breaks
caching
on csrf • different content per session • often breaks
caching
Static Files js / css / images
the best way (tm) • unique filenames + far future
expiration (1 year) or • normal filenames, short expiration (5 min) or • normal filenames, CDN only expiration (and flush the CDN after changes)
Page Caching in Django
Middleware
validation • CommonMiddleware • adds an ETag to the response
if there is none • Conditional GET for ETag • generates new 304 response if ETag matches (keeps cookies)
validation • ConditionalGetMiddleware • Conditional GET for ETag and Last-Modified
• changes the response status code to 304 if conditions match
validation • @etag, @last_modified, @condition • callables for ETag or
Last-Modified calculation • best server performance • most RFC compliant
validation • GZipMiddleware • breaks Django’s ETag handling • changes
ETag in response
expiration • FetchFromCacheMiddleware has to be last: after everything
that modifies the Vary-Header • UpdateCacheMiddleware has to be first: before everything that modifies the Vary-Header
Middleware
vary • SessionMiddleware adds Cookie • GZipMiddleware adds Accept-Encoding •
LocaleMiddleware adds Accept-Language • @vary_on_cookie, @vary_on_headers
Django sucks here but it’s right
expiration breaks • when you use sessions • when you
use CSRF protection (which uses cookies) • when you use google analytics
easy (wrong) way • drop vary header in custom middleware
(security risk, wrong data)
possible but hard way • Middleware to filter google analytics
cookies and add them back later they have no effect on the content • be very careful with using the session / user in your views • be very careful with using forms (which use CSRF Protection)
other ways • don’t use normal expiration headers • only
flushable store (local cache, CDN) • flush the cache (for example) when the database changes
not included • @cache_control (private, public, revalidate, …) • stale
expire headers