mirror of
https://github.com/g0ldyy/comet.git
synced 2026-01-12 01:16:12 +01:00
feat: add manifest and configure page caching settings
This commit is contained in:
@@ -290,3 +290,11 @@ HTTP_CACHE_PRIVATE_STREAMS_TTL=60 # 1 minute (recommended: 30-120)
|
||||
# Stale-While-Revalidate: serve stale content while fetching fresh in background
|
||||
# Improves perceived performance - users get instant response with cached data
|
||||
HTTP_CACHE_STALE_WHILE_REVALIDATE=60 # 1 minute
|
||||
|
||||
# MANIFEST TTL (for /manifest.json and /{config}/manifest.json)
|
||||
# Manifest rarely changes, can be cached longer
|
||||
HTTP_CACHE_MANIFEST_TTL=86400 # 24 hours (recommended: 3600-86400)
|
||||
|
||||
# CONFIGURE page TTL (for /configure and /{config}/configure)
|
||||
# Static page, can be cached for a long time
|
||||
HTTP_CACHE_CONFIGURE_TTL=86400 # 24 hours (recommended: 3600-86400)
|
||||
|
||||
@@ -436,7 +436,7 @@ def log_startup_info(settings):
|
||||
logger.log("COMET", f"Custom Header HTML: {bool(settings.CUSTOM_HEADER_HTML)}")
|
||||
|
||||
http_cache_info = (
|
||||
f" - Public Streams TTL: {settings.HTTP_CACHE_PUBLIC_STREAMS_TTL}s - Private Streams TTL: {settings.HTTP_CACHE_PRIVATE_STREAMS_TTL}s - Stale While Revalidate: {settings.HTTP_CACHE_STALE_WHILE_REVALIDATE}s"
|
||||
f" - Public Streams TTL: {settings.HTTP_CACHE_PUBLIC_STREAMS_TTL}s - Private Streams TTL: {settings.HTTP_CACHE_PRIVATE_STREAMS_TTL}s - Manifest TTL: {settings.HTTP_CACHE_MANIFEST_TTL}s - Configure TTL: {settings.HTTP_CACHE_CONFIGURE_TTL}s - SWR: {settings.HTTP_CACHE_STALE_WHILE_REVALIDATE}s"
|
||||
if settings.HTTP_CACHE_ENABLED
|
||||
else ""
|
||||
)
|
||||
|
||||
@@ -141,6 +141,8 @@ class AppSettings(BaseSettings):
|
||||
HTTP_CACHE_PUBLIC_STREAMS_TTL: Optional[int] = 300
|
||||
HTTP_CACHE_PRIVATE_STREAMS_TTL: Optional[int] = 60
|
||||
HTTP_CACHE_STALE_WHILE_REVALIDATE: Optional[int] = 60
|
||||
HTTP_CACHE_MANIFEST_TTL: Optional[int] = 86400
|
||||
HTTP_CACHE_CONFIGURE_TTL: Optional[int] = 86400
|
||||
|
||||
@field_validator("INDEXER_MANAGER_TYPE")
|
||||
def set_indexer_manager_type(cls, v, values):
|
||||
|
||||
@@ -187,21 +187,23 @@ class CachePolicies:
|
||||
def manifest():
|
||||
"""
|
||||
For manifest.json responses.
|
||||
Very short cache as it can change based on config.
|
||||
Long cache as manifest rarely changes.
|
||||
"""
|
||||
return CacheControl().private().max_age(60).must_revalidate()
|
||||
ttl = settings.HTTP_CACHE_MANIFEST_TTL
|
||||
swr = settings.HTTP_CACHE_STALE_WHILE_REVALIDATE
|
||||
|
||||
return CacheControl().public().max_age(ttl).stale_while_revalidate(swr)
|
||||
|
||||
@staticmethod
|
||||
def configure_page():
|
||||
"""
|
||||
For the /configure page.
|
||||
Cacheable if no custom HTML, otherwise private.
|
||||
Long cache as the page is mostly static.
|
||||
"""
|
||||
ttl = settings.HTTP_CACHE_CONFIGURE_TTL
|
||||
swr = settings.HTTP_CACHE_STALE_WHILE_REVALIDATE
|
||||
|
||||
if settings.CUSTOM_HEADER_HTML:
|
||||
return CacheControl().private().max_age(300)
|
||||
|
||||
return CacheControl().public().max_age(300).s_maxage(3600)
|
||||
return CacheControl().public().max_age(ttl).stale_while_revalidate(swr)
|
||||
|
||||
@staticmethod
|
||||
def empty_results():
|
||||
|
||||
@@ -20,12 +20,23 @@ Cache the configuration page.
|
||||
* **Action**: Eligible for Cache
|
||||
* **Edge TTL**: Use cache-control header if present (first option)
|
||||
* **Browser TTL**: Respect origin
|
||||
* **Serve stale content while revalidating**: On
|
||||
|
||||
## 3. Tiered Cache
|
||||
## 3. Manifest (Cache Rule)
|
||||
Cache the add-on manifest.
|
||||
|
||||
* **Rule Name**: Manifest
|
||||
* **Expression**: `(http.request.uri.path contains "/manifest.json")`
|
||||
* **Action**: Eligible for Cache
|
||||
* **Edge TTL**: Use cache-control header if present (first option)
|
||||
* **Browser TTL**: Respect origin
|
||||
* **Serve stale content while revalidating**: On
|
||||
|
||||
## 4. Tiered Cache
|
||||
Enable **Tiered Cache** in **Caching > Tiered Cache**.
|
||||
This minimizes requests to your origin by checking other Cloudflare datacenters first.
|
||||
|
||||
## 4. Network Optimizations
|
||||
## 5. Network Optimizations
|
||||
In **Speed > Protocol**:
|
||||
|
||||
* **HTTP/3 (QUIC)**: On (faster connections, especially on mobile)
|
||||
|
||||
Reference in New Issue
Block a user