feat: Implement Phase 3 Feed Caching (Partial)
Implements feed caching layer with LRU eviction, TTL expiration, and ETag support. Phase 3.1: Feed Caching (Complete) - LRU cache with configurable max_size (default: 50 feeds) - TTL-based expiration (default: 300 seconds = 5 minutes) - SHA-256 checksums for cache keys and ETags - Weak ETag generation (W/"checksum") - If-None-Match header support for 304 Not Modified responses - Cache invalidation (全体 or per-format) - Hit/miss/eviction statistics tracking - Content-based cache keys (changes when notes are modified) Implementation: - Created starpunk/feeds/cache.py with FeedCache class - Integrated caching into feed routes (RSS, ATOM, JSON Feed) - Added ETag headers to all feed responses - 304 Not Modified responses for conditional requests - Configuration: FEED_CACHE_ENABLED, FEED_CACHE_MAX_SIZE - Global cache instance with singleton pattern Architecture: - Two-level caching: 1. Note list cache (simple dict, existing) 2. Feed content cache (LRU with TTL, new) - Cache keys include format + notes checksum - Checksums based on note IDs + updated timestamps - Non-streaming generators used for cacheable content Testing: - 25 comprehensive cache tests (100% passing) - Tests for LRU eviction, TTL expiration, statistics - Tests for checksum generation and consistency - Tests for ETag generation and uniqueness - All 114 feed tests passing (no regressions) Quality Metrics: - 114/114 tests passing (100%) - Zero breaking changes - Full backward compatibility - Cache disabled mode supported (FEED_CACHE_ENABLED=false) Performance Benefits: - Database queries reduced (note list cached) - Feed generation reduced (content cached) - Bandwidth saved (304 responses) - Memory efficient (LRU eviction) Note: Phase 3 is partially complete. Still pending: - Feed statistics dashboard - OPML 2.0 export endpoint 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,9 @@ Exports:
|
||||
generate_json_feed_streaming: Generate JSON Feed 1.1 with streaming
|
||||
negotiate_feed_format: Content negotiation for feed formats
|
||||
get_mime_type: Get MIME type for a format name
|
||||
get_cache: Get global feed cache instance
|
||||
configure_cache: Configure global feed cache
|
||||
FeedCache: Feed caching class
|
||||
"""
|
||||
|
||||
from .rss import (
|
||||
@@ -38,6 +41,12 @@ from .negotiation import (
|
||||
get_mime_type,
|
||||
)
|
||||
|
||||
from .cache import (
|
||||
FeedCache,
|
||||
get_cache,
|
||||
configure_cache,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# RSS functions
|
||||
"generate_rss",
|
||||
@@ -54,4 +63,8 @@ __all__ = [
|
||||
# Content negotiation
|
||||
"negotiate_feed_format",
|
||||
"get_mime_type",
|
||||
# Caching
|
||||
"FeedCache",
|
||||
"get_cache",
|
||||
"configure_cache",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user