cache

package
v0.8.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache 实现反搜响应的文件缓存:key 为 source + 原图 SHA-256, 只保存规范化响应与写入时间(不保存图片、鉴权 header 或 JavDB 详情), 原子写入 0600,TTL 默认 30 天。

Index

Constants

View Source
const DefaultTTL = 30 * 24 * time.Hour

DefaultTTL 是缓存条目默认有效期(30 天)。

Variables

This section is empty.

Functions

func SortedSources

func SortedSources(stats map[string]int) []string

SortedSources 返回统计中的 source 名列表(升序)。

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 是目录化的反搜响应缓存;每个 source 一个 JSON 文件。

func New

func New(dir string, ttl time.Duration) *Store

New 创建缓存 store;ttl <= 0 时使用 DefaultTTL。

func (*Store) Clear

func (s *Store) Clear(source string) error

Clear 清空指定 source 的缓存;source 为空时清空全部反搜缓存。

func (*Store) Get

func (s *Store) Get(source, key string) (*provider.Response, bool, error)

Get 读取 source 的 key 缓存;过期条目是正常 miss(惰性清理),损坏或读取 失败显式报错,绝不伪装成 miss。

func (*Store) Put

func (s *Store) Put(source, key string, response *provider.Response) error

Put 写入 source 的 key 缓存;已有损坏缓存显式报错,不静默覆盖。

func (*Store) Stats

func (s *Store) Stats() (map[string]int, error)

Stats 返回每个 source 的条目数(按名称排序,便于稳定输出)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL