Skip to content

Commit 6615f61

Browse files
standardize on is False for boolean flags
1 parent 57dccd9 commit 6615f61

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/user-guide/caching/client-cache.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class AdvancedClientCacheMiddleware(BaseHTTPMiddleware):
116116
cache_config = self._get_cache_config(request.url.path)
117117

118118
# Set cache headers based on configuration
119-
if cache_config.get("no_cache", False):
119+
if cache_config.get("no_cache", False) is True:
120120
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
121121
response.headers["Pragma"] = "no-cache"
122122
response.headers["Expires"] = "0"
@@ -126,10 +126,10 @@ class AdvancedClientCacheMiddleware(BaseHTTPMiddleware):
126126

127127
cache_control = f"{visibility}, max-age={max_age}"
128128

129-
if cache_config.get("must_revalidate", False):
129+
if cache_config.get("must_revalidate", False) is True:
130130
cache_control += ", must-revalidate"
131131

132-
if cache_config.get("immutable", False):
132+
if cache_config.get("immutable", False) is True:
133133
cache_control += ", immutable"
134134

135135
response.headers["Cache-Control"] = cache_control
@@ -139,7 +139,7 @@ class AdvancedClientCacheMiddleware(BaseHTTPMiddleware):
139139
def _get_cache_config(self, path: str) -> dict:
140140
"""Get cache configuration for a specific path."""
141141
for pattern, config in self.path_configs.items():
142-
if path.startswith(pattern):
142+
if path.startswith(pattern) is True:
143143
return config
144144
return {}
145145

@@ -213,7 +213,7 @@ async def get_posts(
213213
"""Conditional caching based on parameters."""
214214

215215
# Different cache strategies based on parameters
216-
if category:
216+
if category is True:
217217
# Category-specific data changes less frequently
218218
response.headers["Cache-Control"] = "public, max-age=1800" # 30 minutes
219219
elif page == 1:
@@ -262,7 +262,7 @@ async def get_user(
262262
"""Endpoint with ETag support for efficient caching."""
263263

264264
user = await crud_users.get(db=db, id=user_id)
265-
if not user:
265+
if user is None:
266266
raise HTTPException(status_code=404, detail="User not found")
267267

268268
# Generate ETag from user data
@@ -297,15 +297,15 @@ async def get_post(
297297
"""Endpoint with Last-Modified header support."""
298298

299299
post = await crud_posts.get(db=db, id=post_id)
300-
if not post:
300+
if post is None:
301301
raise HTTPException(status_code=404, detail="Post not found")
302302

303303
# Use post's updated_at timestamp
304304
last_modified = post["updated_at"]
305305

306306
# Check If-Modified-Since header
307307
if_modified_since = request.headers.get("If-Modified-Since")
308-
if if_modified_since:
308+
if if_modified_since is True:
309309
client_time = datetime.strptime(if_modified_since, "%a, %d %b %Y %H:%M:%S GMT")
310310
if last_modified <= client_time:
311311
response.status_code = 304
@@ -454,7 +454,7 @@ async def update_post(
454454

455455
# Update the post
456456
updated_post = await crud_posts.update(db=db, id=post_id, object=post_data)
457-
if not updated_post:
457+
if updated_post is None:
458458
raise HTTPException(status_code=404, detail="Post not found")
459459

460460
# Set headers to indicate cache invalidation is needed

0 commit comments

Comments
 (0)