Skip to content

feat(cache): implement P1 nginx parity support#68

Merged
vansour merged 2 commits intomainfrom
feat/cache-p1-nginx-parity
Apr 28, 2026
Merged

feat(cache): implement P1 nginx parity support#68
vansour merged 2 commits intomainfrom
feat/cache-p1-nginx-parity

Conversation

@vansour
Copy link
Copy Markdown
Owner

@vansour vansour commented Apr 28, 2026

Summary

  • add P1 cache config/runtime support for min-uses admission, ignore-header overrides, exact bounded single-range caching, and cache loader/manager/path tunables
  • extend cache tests and fixtures, and split helper modules so the modularization gate stays green
  • update CACHE_SUPPORT_PLAN.md to mark P1 complete and document the delivered range-caching boundary

Testing

  • cargo fmt --all
  • cargo test -q -p rginx-config --lib
  • cargo test -q -p rginx-http --lib
  • cargo test -q --workspace
  • ./scripts/run-clippy-gate.sh
  • python3 ./scripts/run-modularization-gate.py

Copilot AI review requested due to automatic review settings April 28, 2026 09:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Warning

Rate limit exceeded

@vansour has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 32 minutes and 15 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7ed53d74-33a1-4d41-8bb9-542d53fd3994

📥 Commits

Reviewing files that changed from the base of the PR and between 539394c and 16dafc7.

📒 Files selected for processing (13)
  • crates/rginx-config/src/validate/cache.rs
  • crates/rginx-config/src/validate/tests/cache.rs
  • crates/rginx-http/src/cache/entry.rs
  • crates/rginx-http/src/cache/load.rs
  • crates/rginx-http/src/cache/policy.rs
  • crates/rginx-http/src/cache/request.rs
  • crates/rginx-http/src/cache/store.rs
  • crates/rginx-http/src/cache/store/maintenance.rs
  • crates/rginx-http/src/cache/tests/lookup/keys.rs
  • crates/rginx-http/src/cache/tests/storage_p1.rs
  • crates/rginx-http/src/state/tests/snapshots.rs
  • crates/rginx-http/src/state/tests/status.rs
  • crates/rginx-http/src/state/tests/support.rs
📝 Walkthrough

概览

该PR实现了HTTP缓存系统的P1功能特性,包括缓存区域调优参数(路径分片级别、加载器/管理器批处理和睡眠时间)、路由级缓存控制(最小使用次数阈值、忽略特定响应头、范围请求处理策略)、范围请求缓存支持和基于最小使用次数的准入控制。

变更

内聚体 / 文件 摘要
配置模型和编译
crates/rginx-config/src/model/cache.rs, crates/rginx-config/src/model.rs, crates/rginx-config/src/compile/cache.rs, crates/rginx-config/src/compile/tests/cache.rs, crates/rginx-config/src/compile/tests/cache_p1.rs
添加新的缓存区域字段(path_levels、loader/manager批处理和睡眠参数、inactive_cleanup_interval_secs)和路由缓存字段(min_uses、ignore_headers、range_requests);编译器现在将这些配置参数转换为核心策略对象;新增P1功能的编译测试验证配置正确转换。
配置验证
crates/rginx-config/src/validate/cache.rs, crates/rginx-config/src/validate/cache/predicate.rs, crates/rginx-config/src/validate/tests/cache.rs
扩展验证以强制新字段的约束(min_uses > 0、ignore_headers非空、path_levels非空且每个级别 > 0);提取谓词验证逻辑至新的predicate模块;添加新的验证测试覆盖无效字段值。
核心配置结构
crates/rginx-core/src/config/cache.rs, crates/rginx-core/src/config.rs, crates/rginx-core/src/lib.rs
向CacheZone和RouteCachePolicy添加新的公开字段;添加CacheIgnoreHeader和CacheRangeRequestPolicy枚举类型;更新模块级重导出以暴露新类型。
缓存路径解析
crates/rginx-http/src/cache/entry.rs, crates/rginx-http/src/cache/lookup.rs, crates/rginx-http/src/cache/runtime.rs, crates/rginx-http/src/cache/runtime/support.rs
添加cache_paths_for_zone函数以支持可配置的目录嵌套级别;更新缓存元数据/正文路径计算以使用新的路径级别参数而非硬编码的2字符前缀。
缓存加载和批处理
crates/rginx-http/src/cache/load.rs, crates/rginx-http/src/cache/manager.rs, crates/rginx-http/src/cache/mod.rs
用递归的scan_cache_dir函数替换前缀扫描方式;实现LoaderState以在达到配置的batch_entries时进行批处理和睡眠;在CacheZoneRuntime中添加last_inactive_cleanup_unix_ms时间戳;在CacheIndex中添加admission_counts映射。
范围请求处理
crates/rginx-http/src/cache/request.rs, crates/rginx-http/src/cache/tests/lookup/keys.rs
添加cacheable_range_request和response_content_range_matches_request函数以验证范围请求;修改缓存键以包含范围信息(
缓存策略和头处理
crates/rginx-http/src/cache/policy.rs, crates/rginx-http/src/cache/policy/directives.rs, crates/rginx-http/src/cache/store/helpers.rs
实现ignore_headers配置以绕过特定头部的缓存决策(X-Accel-Expires、Expires、Cache-Control、Set-Cookie、Vary);抽取指令解析至新的directives模块;更新vary_is_supported和cache_vary_values以支持头部忽略。
缓存准入和维护
crates/rginx-http/src/cache/store.rs, crates/rginx-http/src/cache/store/maintenance.rs
添加record_cache_admission_attempt函数实现基于min_uses的准入控制;实现间隔节流的非活跃清理(使用last_inactive_cleanup_unix_ms);添加批处理和睡眠支持;在清理时同步删除admission_counts记录。
文档和计划
CACHE_SUPPORT_PLAN.md
更新交付追踪以标记P1功能为已完成;记录新的可调参数和行为;更新后续P2工作的建议顺序。
测试套件
crates/rginx-http/src/cache/tests/mod.rs, crates/rginx-http/src/cache/tests/storage_p1.rs, crates/rginx-http/src/cache/tests/lookup/keys.rs, crates/rginx-http/src/proxy/tests/cache.rs, crates/rginx-http/src/state/tests/...
添加新的storage_p1测试模块以验证端到端的存储、准入控制、范围缓存和清理行为;更新现有测试以初始化新的策略字段;扩展缓存区域配置以包括新的调优参数。
运行时调度
crates/rginx-runtime/src/cache.rs
将非活跃清理轮询间隔从60秒改为1秒。

序列图

sequenceDiagram
    participant Client
    participant CacheStore as Cache Store<br/>(准入/存储)
    participant CacheIndex as Cache Index<br/>(admission_counts)
    participant CacheManager as Cache Manager<br/>(lookup)
    participant Disk as Disk<br/>(path_levels)

    Client->>CacheStore: 请求(range?)<br/>min_uses=N
    alt 新条目
        CacheStore->>CacheIndex: 查询admission_count
        CacheIndex-->>CacheStore: 当前计数 < N
        CacheStore->>CacheStore: 跳过存储<br/>返回响应
    else 第N次请求
        CacheStore->>CacheIndex: 增加admission_count
        CacheIndex-->>CacheStore: 计数 >= N
        CacheStore->>Disk: 使用path_levels<br/>写入元数据/正文
        Disk-->>CacheStore: 保存完成
    end
    
    Client->>CacheManager: 后续请求<br/>相同key/range?
    CacheManager->>CacheIndex: 查询缓存
    CacheIndex-->>CacheManager: 返回条目
    alt 范围匹配
        CacheManager->>Disk: 读取缓存<br/>使用path_levels
        Disk-->>CacheManager: 正文
        CacheManager-->>Client: 206/完整响应
    else 范围不匹配
        CacheManager-->>Client: 缓存未命中
    end
Loading
sequenceDiagram
    participant Manager as Cleanup<br/>Manager
    participant ZoneRuntime as Zone Runtime<br/>(last_inactive_<br/>cleanup_unix_ms)
    participant Index as Cache Index
    participant Disk as Disk Files

    Manager->>ZoneRuntime: 检查上次清理时间
    alt 间隔未达到
        Manager->>Manager: 跳过清理
    else 需要清理
        Manager->>Index: 查询非活跃条目<br/>(按时间排序)
        Index-->>Manager: 返回条目列表
        loop 批处理循环<br/>(manager_batch_entries)
            Manager->>Disk: 删除文件
            Manager->>Index: 删除条目<br/>& admission_counts
            Manager->>Manager: 批处理睡眠<br/>(manager_sleep)
        end
        Manager->>ZoneRuntime: 更新last_inactive_<br/>cleanup_unix_ms
    end
Loading

预估代码审查工作量

🎯 4 (复杂) | ⏱️ ~75 分钟

可能相关的PR

  • feat: add route response cache MVP #65: 主PR扩展并修改了PR #65引入的路由级HTTP缓存子系统——添加新的配置/模型字段(path_levels、min_uses、ignore_headers、range策略)、运行时调优(loader/manager批处理、非活跃清理)和相关的缓存路径、准入和范围处理逻辑,因此在代码级别上直接相关。

  • Complete cache support phases 4-6 #66: 主PR与PR #66相关——两者都修改相同的缓存子系统文件和功能(缓存路径分片/路径、loader/manager扫描和非活跃清理、range/min_uses/ignore-headers策略、store/load/maintenance逻辑和相关辅助函数),表明对缓存实现的重叠代码级别更改。

  • feat(cache): implement P0 nginx parity support #67: 两个PR修改相同的缓存子系统(config/model/compile/validate和许多crates/rginx-http缓存模块)以添加互补的缓存功能(P0: bypass/ttl/vary/background-update/lock; 主PR: P1: min_uses、范围缓存、ignore-headers、path_levels、loader/manager调优和准入计数),因此在代码级别上相关。

🐰 缓存之道新时代

路径分片百般妙,范围缓存齐绽放,
准入门槛把关卡,头部甄选细琢磨,
清理批处理优雅,调优参数尽相宜! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.40% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确总结了主要变化:实现P1 nginx奇偶性缓存支持,涵盖最小使用次数、忽略头、范围缓存和加载器/管理器/路径可调参数。
Description check ✅ Passed 描述清晰相关,列出了所有主要变化:P1缓存配置、最小使用次数、忽略头、范围缓存、加载器/管理器/路径可调参数、测试扩展和文档更新。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cache-p1-nginx-parity

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@amazon-q-developer amazon-q-developer Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR successfully implements P1 nginx cache parity support with comprehensive features including min-uses admission control, ignore-header overrides, bounded single-range caching, and cache loader/manager/path tunables. The implementation is thorough with proper error handling, validation, and extensive test coverage across 34 files. The code quality is high with no blocking issues identified.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.


⚠️ This PR contains more than 30 files. Amazon Q is better at reviewing smaller PRs, and may miss issues in larger changesets.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements several 'P1' level caching features, including cache_min_uses for admission control, configurable path_levels for disk layout, and support for route-level proxy_ignore_headers. It also introduces a basic model for caching single-segment bounded range requests. Feedback focuses on optimizing the inactive entry cleanup algorithm to avoid $O(N^2)$ complexity, adding validation to ensure path_levels do not exceed the hash length, and refining the directory prefix fallback logic.

Comment thread crates/rginx-http/src/cache/store/maintenance.rs Outdated
Comment thread crates/rginx-config/src/validate/cache.rs
Comment thread crates/rginx-http/src/cache/entry.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements “P1 nginx parity” cache features across config, compile/validate, runtime cache behavior, and adds targeted tests/fixtures while keeping within the modularization constraints.

Changes:

  • Extend cache config + runtime to support min_uses admission, proxy_ignore_headers-style overrides, and bounded single-range (Range/206) caching.
  • Add cache-zone tunables (path_levels, loader/manager batch+sleep, inactive cleanup interval) and update maintenance/load paths accordingly.
  • Expand compile/validate coverage and add new cache P1 test modules + update CACHE_SUPPORT_PLAN.md to mark P1 delivered and document boundaries.

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rginx-runtime/src/cache.rs Increase cache cleanup tick frequency to support per-zone cleanup intervals.
crates/rginx-http/src/state/tests/support.rs Update snapshot test helpers for new cache zone fields.
crates/rginx-http/src/state/tests/status.rs Update cache policy test fixtures with new policy fields.
crates/rginx-http/src/state/tests/snapshots.rs Update cache policy test fixtures with new policy fields.
crates/rginx-http/src/proxy/tests/cache.rs Update proxy cache test fixtures with new zone/policy fields.
crates/rginx-http/src/cache/tests/storage_p1.rs Add new P1 storage tests (min_uses, ignore headers, range caching, path levels, batch cleanup).
crates/rginx-http/src/cache/tests/mod.rs Wire new P1 storage tests and update test runtime zone construction.
crates/rginx-http/src/cache/tests/lookup/keys.rs Add range-related bypass/key rendering tests and update fixtures.
crates/rginx-http/src/cache/store/maintenance.rs Add admission count cleanup + batch/sleep-based inactive cleanup and interval gating.
crates/rginx-http/src/cache/store/helpers.rs Allow ignoring Vary when computing vary key components.
crates/rginx-http/src/cache/store.rs Enforce min_uses admission before storing and adopt per-zone cache paths.
crates/rginx-http/src/cache/runtime/support.rs Use per-zone cache paths when cleaning unindexed files.
crates/rginx-http/src/cache/runtime.rs Use per-zone cache paths when serving cached responses.
crates/rginx-http/src/cache/request.rs Implement bounded single-range parsing, range-aware bypass, and range-aware cache keys.
crates/rginx-http/src/cache/policy/directives.rs Extract/cache-control directive parsing helpers.
crates/rginx-http/src/cache/policy.rs Add ignore-header behavior, range-aware storability rules, and refactor directive parsing.
crates/rginx-http/src/cache/mod.rs Add per-zone cleanup state + admission count tracking in cache index.
crates/rginx-http/src/cache/manager.rs Initialize new per-zone cleanup tracking field.
crates/rginx-http/src/cache/lookup.rs Use per-zone cache paths for reading cached metadata/bodies.
crates/rginx-http/src/cache/load.rs Recursively scan cache dirs, support path_levels, and throttle scanning via loader tunables.
crates/rginx-http/src/cache/entry.rs Add cache_paths_for_zone and generalized path-level directory layout support.
crates/rginx-core/src/lib.rs Re-export new cache config enums.
crates/rginx-core/src/config/cache.rs Add zone tunables, min_uses, ignore-header enum, and range request policy enum.
crates/rginx-core/src/config.rs Export new cache config enums from the config module.
crates/rginx-config/src/validate/tests/cache.rs Add validation tests for new cache fields.
crates/rginx-config/src/validate/cache/predicate.rs Split predicate validation into a dedicated module (modularization).
crates/rginx-config/src/validate/cache.rs Validate new zone tunables, min_uses, and ignore-headers constraints.
crates/rginx-config/src/model/cache.rs Add new cache config model fields + enums for ignore headers and range policy.
crates/rginx-config/src/model.rs Re-export new cache model enums.
crates/rginx-config/src/compile/tests/cache_p1.rs Add compile test ensuring P1 cache fields compile into snapshot/runtime config.
crates/rginx-config/src/compile/tests/cache.rs Update compile tests to include new cache fields in fixtures.
crates/rginx-config/src/compile/tests.rs Register new cache P1 compile test module.
crates/rginx-config/src/compile/cache.rs Compile new cache tunables + P1 policy fields with defaults and mappings.
CACHE_SUPPORT_PLAN.md Mark P1 complete and document the delivered bounded single-range caching boundary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/rginx-http/src/cache/load.rs
Comment thread crates/rginx-http/src/cache/store/maintenance.rs
Comment thread crates/rginx-http/src/cache/store/maintenance.rs
coderabbitai[bot]
coderabbitai Bot previously requested changes Apr 28, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/rginx-http/src/state/tests/status.rs (1)

279-296: 🧹 Nitpick | 🔵 Trivial

建议把这里的 RouteCachePolicy 测试字面量抽成共享 helper。

现在状态测试里已经有多处手写同一组策略字段,这次新增 min_usesignore_headersrange_requests 后又需要同步补齐。提成 builder/fixture 可以减少后续 P2/P3 扩字段时的漂移风险。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/rginx-http/src/state/tests/status.rs` around lines 279 - 296, Multiple
tests duplicate the same RouteCachePolicy literal causing maintenance drift;
extract a shared helper/builder that returns a default RouteCachePolicy and use
it across tests. Create a function (e.g., default_route_cache_policy() or
RouteCachePolicy::test_builder()) that sets the common fields (zone, methods,
statuses, key via CacheKeyTemplate::parse("{scheme}:{host}:{uri}"),
ttl_by_status, cache_bypass, no_cache, stale_if_error, use_stale,
background_update, lock_timeout, lock_age, min_uses, ignore_headers,
range_requests) and allow callers to override specific fields in tests; replace
the inline literals in the status tests with calls to that helper to centralize
defaults and avoid future drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/rginx-config/src/validate/tests/cache.rs`:
- Around line 158-167: Add a new unit test that mirrors
validate_rejects_empty_path_levels but sets CacheZoneConfig.path_levels to
Some(vec![0]) to exercise the validate_path_levels branch that rejects
zero-valued levels; call validate(&config) and assert it returns an Err whose
message mentions the invalid zero level (e.g. contains "path_levels must be > 0"
or similar). Place the test in the same test module alongside
validate_rejects_empty_path_levels and name it something like
validate_rejects_zero_path_level so validate_path_levels,
CacheZoneConfig.path_levels and validate are exercised.

In `@crates/rginx-http/src/cache/load.rs`:
- Around line 57-63: The recursive call in scan_cache_dir currently propagates
errors with ? (when recursing into subdirectories, lines around the recursive
call in fn scan_cache_dir), which makes any unreadable child dir abort the
entire index load; change that behavior to mirror the other branches by catching
the error from the recursive call, logging a warning via loader (or process
logger) with context (path and error), and continue the loop instead of
returning Err; locate the recursive invocation inside scan_cache_dir and replace
the ? propagation with a match or if let Err(e) => { loader.warn(...); continue;
} so scanning proceeds despite unreadable subdirs.

In `@crates/rginx-http/src/cache/policy.rs`:
- Around line 52-53: The code computes requested_range with
cacheable_range_request(&context.request, &context.policy) then calls
status_is_cacheable(context, status) which re-parses the Range; to avoid
duplication change status_is_cacheable to accept the precomputed requested_range
(e.g., add a parameter requested_range: Option<Range> or similar) and pass the
local requested_range into the call, updating all call sites (including the
other occurrence at the second block) to use the new signature so parsing
happens only once; update function name references (status_is_cacheable and
cacheable_range_request) accordingly and ensure any internal logic in
status_is_cacheable uses the provided requested_range instead of calling
cacheable_range_request again.

In `@crates/rginx-http/src/cache/request.rs`:
- Around line 123-135: 在 cacheable_range_request_from_parts 中需要显式拒绝包含多个 Range
头的请求:在尝试解析之前检查 headers 中 Range 头的数量(使用 headers.get_all(RANGE) 或等价 API),如果出现多于 1
个 Range 头则直接返回 None;仅在恰好有且只有一个 Range 头时再调用 headers.get(RANGE)?.to_str().ok()?
并传入 parse_single_bounded_byte_range,以防把多范围请求误判为可缓存单范围请求(参见函数
cacheable_range_request_from_parts 和 parse_single_bounded_byte_range)。

In `@crates/rginx-http/src/cache/store.rs`:
- Around line 89-94: The admission logic uses context.cached_entry.is_some()
(old lookup state) so a response that rebuckets into final_key (e.g. Vary
change) can be incorrectly treated as an existing cache entry and bypass
min_uses; change record_cache_admission_attempt to perform the existence check
for final_key while holding the index lock instead of relying on
context.cached_entry, i.e. pass final_key (and the index lock or a
lookup-closure) into record_cache_admission_attempt, grab the index lock inside
that function, re-check whether final_key currently exists, and only then decide
whether to honor min_uses.

---

Outside diff comments:
In `@crates/rginx-http/src/state/tests/status.rs`:
- Around line 279-296: Multiple tests duplicate the same RouteCachePolicy
literal causing maintenance drift; extract a shared helper/builder that returns
a default RouteCachePolicy and use it across tests. Create a function (e.g.,
default_route_cache_policy() or RouteCachePolicy::test_builder()) that sets the
common fields (zone, methods, statuses, key via
CacheKeyTemplate::parse("{scheme}:{host}:{uri}"), ttl_by_status, cache_bypass,
no_cache, stale_if_error, use_stale, background_update, lock_timeout, lock_age,
min_uses, ignore_headers, range_requests) and allow callers to override specific
fields in tests; replace the inline literals in the status tests with calls to
that helper to centralize defaults and avoid future drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0737e9e4-ca50-4bfc-9e18-54340aa7110f

📥 Commits

Reviewing files that changed from the base of the PR and between 0866042 and 539394c.

📒 Files selected for processing (34)
  • CACHE_SUPPORT_PLAN.md
  • crates/rginx-config/src/compile/cache.rs
  • crates/rginx-config/src/compile/tests.rs
  • crates/rginx-config/src/compile/tests/cache.rs
  • crates/rginx-config/src/compile/tests/cache_p1.rs
  • crates/rginx-config/src/model.rs
  • crates/rginx-config/src/model/cache.rs
  • crates/rginx-config/src/validate/cache.rs
  • crates/rginx-config/src/validate/cache/predicate.rs
  • crates/rginx-config/src/validate/tests/cache.rs
  • crates/rginx-core/src/config.rs
  • crates/rginx-core/src/config/cache.rs
  • crates/rginx-core/src/lib.rs
  • crates/rginx-http/src/cache/entry.rs
  • crates/rginx-http/src/cache/load.rs
  • crates/rginx-http/src/cache/lookup.rs
  • crates/rginx-http/src/cache/manager.rs
  • crates/rginx-http/src/cache/mod.rs
  • crates/rginx-http/src/cache/policy.rs
  • crates/rginx-http/src/cache/policy/directives.rs
  • crates/rginx-http/src/cache/request.rs
  • crates/rginx-http/src/cache/runtime.rs
  • crates/rginx-http/src/cache/runtime/support.rs
  • crates/rginx-http/src/cache/store.rs
  • crates/rginx-http/src/cache/store/helpers.rs
  • crates/rginx-http/src/cache/store/maintenance.rs
  • crates/rginx-http/src/cache/tests/lookup/keys.rs
  • crates/rginx-http/src/cache/tests/mod.rs
  • crates/rginx-http/src/cache/tests/storage_p1.rs
  • crates/rginx-http/src/proxy/tests/cache.rs
  • crates/rginx-http/src/state/tests/snapshots.rs
  • crates/rginx-http/src/state/tests/status.rs
  • crates/rginx-http/src/state/tests/support.rs
  • crates/rginx-runtime/src/cache.rs
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test Fast
  • GitHub Check: Agent
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-13T10:53:29.903Z
Learnt from: vansour
Repo: vansour/rginx PR: 43
File: crates/rginx-config/src/validate/server.rs:421-439
Timestamp: 2026-04-13T10:53:29.903Z
Learning: In `crates/rginx-config/src/validate/server.rs` (`validate_http3`), the check for `tls.session_tickets` when `http3.early_data = true` intentionally only rejects `Some(true)` and allows `None`. Requiring `Some(false)` breaks 0-RTT resumption and the `routes_http3_early_data_by_replay_safety` test and the CI `http3` gate in the current rustls/quinn integration. This is a deliberate design decision and should not be flagged as a bug until the runtime/session policy is updated to support that configuration.

Applied to files:

  • crates/rginx-config/src/compile/tests/cache_p1.rs
  • crates/rginx-config/src/validate/tests/cache.rs
🪛 LanguageTool
CACHE_SUPPORT_PLAN.md

[uncategorized] ~38-~38: 您的意思是“"不"齐”?
Context: ...s 已完成并已落地。 - 下文保留这些条目,是为了把“已交付能力”和“下一轮继续补齐的剩余差距”放在同一张 对标清单里,避免后续阶段重复整理。 - P2 ...

(BU)


[uncategorized] ~107-~107: 您的意思是“"不"齐”?
Context: ...测试中,不会出现无界等待,也不会放大 upstream 压力。 ### P1:补齐大对象场景和维护控制面(当前状态:本 PR 已完成) 目标:支持更接近 NG...

(BU)


[uncategorized] ~213-~213: 您的意思是“"不"配置”?
Context: ...:仅在产品边界明确后,再评估更广协议族缓存 交付原则: - 每个子项都应先补配置模型、再补运行时、最后补 admin/status 和测试。 - P0-3...

(BU)


[uncategorized] ~213-~213: 您的意思是“"不"运行”?
Context: ...界明确后,再评估更广协议族缓存 交付原则: - 每个子项都应先补配置模型、再补运行时、最后补 admin/status 和测试。 - P0-3 与 `P0...

(BU)

🔇 Additional comments (25)
crates/rginx-http/src/cache/policy/directives.rs (1)

5-94: 这组缓存指令解析拆分得很稳。

Cache-Control/Expires/Pragma/X-Accel-Expires 的边界都照顾到了,尤其是 s-maxage 优先级、过期时间钳制到 Duration::ZERO,以及 @<epoch> 绝对时间转换,和这次 P1 行为扩展是对齐的。

crates/rginx-http/src/state/tests/snapshots.rs (1)

140-157: 把 P1 字段显式写进快照 fixture 是对的。

这样测试不会隐式依赖默认值,后续如果 RouteCachePolicy 默认行为再变,快照语义也更稳定。

crates/rginx-config/src/compile/tests.rs (1)

56-58: 这里把 cache_p1 测试模块接入主入口没有问题。

这能确保新增的 P1 编译期覆盖和现有测试套件一起运行,不会因为模块未注册而静默漏测。

crates/rginx-http/src/cache/runtime.rs (1)

95-99: 这里切到 cache_paths_for_zone(...) 是必要的。

serve_stale 也走 zone-aware 路径后,分级目录/分片配置下的 stale body 读取终于和 lookup/store/delete 保持一致了。

crates/rginx-http/src/cache/runtime/support.rs (1)

12-18: 删除路径同步切到 zone-aware 方案是正确的。

否则索引已移除但磁盘文件仍按旧路径查找时,分层目录下会留下孤儿文件。

crates/rginx-http/src/cache/manager.rs (1)

28-37: 这个新运行时字段在构造阶段初始化到位了。

CacheZoneRuntime 的实例化和结构体定义保持同步,避免后续 inactive cleanup 节流逻辑读到未接入的状态。

crates/rginx-http/src/cache/lookup.rs (1)

89-93: lookup 侧这两处路径切换是一致且必要的。

元数据读取和 stale 响应回放都改成按 zone 配置解路径后,命中、过期回放和磁盘布局就不会再出现分叉。

Also applies to: 146-152

crates/rginx-runtime/src/cache.rs (1)

7-10: 轮询粒度调整合理,行为一致性保持良好。

将轮询改为 1 秒后,清理任务触发更及时,且不影响现有 shutdown 退出语义。

crates/rginx-config/src/compile/tests/cache.rs (1)

14-19: 测试夹具对齐完整,兼容性处理正确。

新增字段统一显式置 None,能稳定覆盖“未开启 P1 控制项”场景,保证原有断言语义不被引入性变更污染。

Also applies to: 94-97, 155-157, 196-201, 286-288

crates/rginx-core/src/config.rs (1)

14-16: 公共导出面更新正确。

新增缓存策略类型已同步对外 re-export,和本次 P1 配置能力扩展保持一致。

crates/rginx-config/src/model.rs (1)

13-14: 模型层导出补齐到位。

新增配置类型已进入统一导出面,和缓存配置模型扩展保持一致。

crates/rginx-http/src/state/tests/support.rs (1)

152-157: 测试支持结构更新充分。

缓存 zone 的新调优字段已在测试快照中完整填充,能有效支撑 P1 行为相关测试场景。

crates/rginx-http/src/cache/load.rs (1)

9-10: 路径与加载节流能力接入完整,方向正确。

cache_paths_for_zone 的统一接入和 LoaderState 批次睡眠机制与 P1 目标一致,整体改造思路清晰。

Also applies to: 87-87, 110-110, 196-196, 201-217

crates/rginx-core/src/lib.rs (1)

8-20: 核心库导出面同步准确。

新增缓存策略类型已在 rginx-core 顶层入口正确暴露,便于下游统一依赖。

crates/rginx-http/src/cache/mod.rs (1)

155-159: admission_counts 的清理已正确配对,无需修改。

经核查,所有 entries.remove() 调用均已配对相应的 admission_counts.remove() 调用,且位置恰当。在所有 6 个删除路径中(cleanup_inactive_entriespurge_by_selectorupdate_entry 内的替换和不兼容清理、eviction_candidatesremove_index_entry),admission_counts 的清理与 entries 的删除同步进行,不存在计数残留风险。

crates/rginx-config/src/validate/tests/cache.rs (1)

134-156: P1 新增缓存校验失败路径补充得很到位。

min_usesignore_headers 的负向用例清晰,能有效防止后续校验逻辑回退。

crates/rginx-http/src/proxy/tests/cache.rs (1)

18-20: 测试夹具与 P1 配置模型已保持一致。

路由策略与 zone 运行参数同步补齐,能更真实覆盖新缓存行为。

Also applies to: 92-98, 156-162

crates/rginx-http/src/cache/tests/mod.rs (1)

17-18: 测试基座升级完整,便于后续 P1 用例复用。

CacheZoneRuntimeRouteCachePolicy 的默认测试构造已覆盖新增字段,方向正确。

Also applies to: 37-49, 90-93, 133-136

crates/rginx-http/src/cache/tests/lookup/keys.rs (1)

170-198: Range 请求的关键行为覆盖很扎实。

默认旁路与启用缓存后 key 拼接两条路径都已验证,回归价值高。

Also applies to: 200-232

crates/rginx-http/src/cache/store/helpers.rs (1)

33-39: ignore_headersVary 的短路处理实现正确。

Line [37]-Line [39] 的提前返回逻辑清晰,能确保策略生效于存储路径。

crates/rginx-config/src/compile/cache.rs (1)

67-88: P1 编译映射实现完整且一致。

zone 与 route policy 的新增字段都已落地到核心结构,默认值策略也清晰。

Also applies to: 167-179, 249-264

crates/rginx-config/src/compile/tests/cache_p1.rs (1)

4-143: P1 编译行为回归测试覆盖面充分。

对 zone 参数与 route policy 参数都做了结果级断言,能有效保护编译层改动。

crates/rginx-config/src/validate/cache.rs (1)

29-40: 缓存配置校验扩展实现扎实。

新增字段的边界检查完整,且 path_levels 独立函数化后可维护性更好。

Also applies to: 158-168, 173-186

crates/rginx-http/src/cache/policy.rs (1)

56-67: Range 与响应头一致性校验实现正确。

这里把“请求 Range 可缓存性、206 状态、Content-Range 精确匹配、非忽略场景下的 Set-Cookie/Cache-Control 拦截”串成统一判定链,行为边界清晰,能有效降低错误对象入缓存的风险。

Also applies to: 68-81

crates/rginx-http/src/cache/request.rs (1)

75-80: Range key 维度与 Content-Range 回包校验配合良好。

把请求端可缓存范围写入 key,并在响应端做精确起止位匹配,能够有效避免不同分片互相污染缓存。

Also applies to: 91-121, 137-149

Comment thread crates/rginx-config/src/validate/tests/cache.rs
Comment thread crates/rginx-http/src/cache/load.rs Outdated
Comment thread crates/rginx-http/src/cache/policy.rs Outdated
Comment thread crates/rginx-http/src/cache/request.rs
Comment thread crates/rginx-http/src/cache/store.rs Outdated
@vansour
Copy link
Copy Markdown
Owner Author

vansour commented Apr 28, 2026

Addressed the current review findings in 16dafc7.

Changes in this follow-up:

  • fixed min_uses admission to re-check the final cache key under the index lock
  • explicitly reject requests with multiple Range headers and added a regression test
  • removed duplicated range parsing in cache policy checks
  • made cache loader directory scanning resilient to unreadable subdirectories and avoided blocking Tokio worker threads during throttled loader sleeps
  • validated path_levels total length against the 64-char cache hash, added missing validation tests, and removed the magic "00" fallback in cache path segment generation
  • refactored inactive cleanup batching to collect/sort inactive keys once per run instead of rescanning and resorting every batch
  • extracted a shared state-test cache policy helper to remove duplicated RouteCachePolicy literals

Verification rerun locally:

  • cargo fmt --all
  • cargo test -q --workspace
  • cargo test -q -p rginx-http --lib
  • ./scripts/run-clippy-gate.sh
  • python3 ./scripts/run-modularization-gate.py

@vansour vansour dismissed coderabbitai[bot]’s stale review April 28, 2026 10:30

Addressed in 16dafc7; follow-up CodeRabbit rerun failed due to external rate limiting, not unresolved code issues.

@vansour vansour merged commit 90590d5 into main Apr 28, 2026
7 checks passed
@vansour vansour deleted the feat/cache-p1-nginx-parity branch April 28, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants