Skip to content

Conversation

@varg1714
Copy link
Contributor

@varg1714 varg1714 commented Oct 24, 2025

Description / 描述

支持自定义文件路径的缓存时间,* 匹配单层目录,** 匹配多层目录。配置方式如下:

/文件/历史存档/**:300
/文件/本月新增/**:30
/音乐/*:60
/游戏/*/**:60

按照以上规则,缓存方式如下:

  • /文件/历史存档 目录及其子目录下所有文件将被缓存300分钟
  • /文件/本月新增 目录及其子目录下所有文件将被缓存30分钟
  • 历史存档本月新增 这两个目录外,/文件 目录及其子目录将应用驱动的默认缓存时间
  • /音乐 目录下的所有文件将被缓存30分钟,不包括子目录。例如 /音乐/A/B 将不会命中规则
  • /游戏 目录下的子目录将会命中规则,例如 /游戏/A 目录下的文件将会被缓存60分钟,但直属于 '/游戏' 目录下的文件将应用驱动的默认缓存时间

规则遵循优先匹配的原则,上面的规则越先命中

Motivation and Context / 背景

当前目录的缓存时间统一由 cache_expiration 控制,实际使用中不同目录下的资源更新频率不同,基于此功能可以单独给这些目录设置更长/更短的缓存时间。

How Has This Been Tested? / 测试

通过指定不同路径的缓存时间测试每个路径的缓存规则。

Checklist / 检查清单

  • I have read the CONTRIBUTING document.
    我已阅读 CONTRIBUTING 文档。
  • I have formatted my code with go fmt or prettier.
    我已使用 go fmtprettier 格式化提交的代码。
  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).
    我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
  • I have requested review from relevant code authors using the "Request review" feature when applicable.
    我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
  • I have updated the repository accordingly (If it’s needed).
    我已相应更新了相关仓库(若适用)。

@ILoveScratch2 ILoveScratch2 requested a review from Copilot October 25, 2025 13:24
Copy link
Contributor

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

This PR introduces support for customizing cache expiration times for specific paths in storage drivers. The feature allows users to define path-specific cache policies using glob patterns, enabling more granular control over cache behavior based on directory structure and content update frequency.

Key Changes:

  • Added custom cache policy configuration field to the storage model
  • Implemented path matching logic using glob patterns to determine cache TTL
  • Added a new dependency (doublestar/v4) for glob pattern matching

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.

File Description
internal/model/storage.go Added CustomCachePolicies field to store custom cache rules as text
internal/op/driver.go Added driver configuration item for custom cache policies
internal/op/fs.go Implemented cache policy parsing and path matching logic to determine TTL
go.mod Added bmatcuk/doublestar/v4 dependency for glob pattern matching

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

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.

1 participant