downloadcache

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 17 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 downloadcache 管理 MCP 领取文件;文件名保存有效期,授权密钥仅存在于本次服务内存中。

Index

Constants

View Source
const (
	MaxArtifactSize int64 = 1 << 30
	RoutePrefix           = "/mcp/downloads/"
)

Variables

View Source
var (
	ErrTooLarge     = errors.New("传输文件超过大小限制")
	ErrCapacity     = errors.New("领取缓存额度不足")
	ErrBusy         = errors.New("HTTP 领取并发已满")
	ErrExpired      = errors.New("下载链接已过期")
	ErrNotFound     = errors.New("领取文件不存在")
	ErrInvalidToken = errors.New("下载链接凭据无效")
	ErrInvalidName  = errors.New("领取文件名无效")
	ErrClosed       = errors.New("领取缓存已停止")
	ErrOwned        = errors.New("领取缓存已由其他实例管理")
	ErrSizeMismatch = errors.New("传输文件大小与预期不符")
)

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	Name         string
	DownloadName string
	Size         int64
	ExpiresAt    time.Time
}

type Lease

type Lease struct {
	File         *os.File
	Size         int64
	ExpiresAt    time.Time
	DownloadName string
	// contains filtered or unexported fields
}

func (*Lease) Close

func (l *Lease) Close() error

type Options

type Options struct {
	Directory                                   string
	Now                                         func() time.Time
	TTL, ScanInterval, LockTimeout              time.Duration
	MaxFileSize, MaxBytes                       int64
	MaxFiles, MaxTransfers, MaxTransfersPerFile int
	// OnCleanupError 接收后台清理失败;失败文件仍占用额度。
	OnCleanupError func(error)
}

type Pending

type Pending struct {
	File *os.File
	// contains filtered or unexported fields
}

func (*Pending) Abort

func (p *Pending) Abort() error

func (*Pending) Commit

func (p *Pending) Commit(downloadName string) (Artifact, error)

type Store

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

func New

func New(options Options) (*Store, error)

func (*Store) Begin

func (s *Store) Begin(size int64, suffix string) (*Pending, error)

func (*Store) Close

func (s *Store) Close() error

Close 立即拒绝新领取,通知 HTTP 结束现有请求;最后一个句柄释放后才交还目录独占权。

func (*Store) Done

func (s *Store) Done() <-chan struct{}

func (*Store) Import

func (s *Store) Import(ctx context.Context, source string, size int64, suffix, downloadName string) (artifact Artifact, err error)

Import 复用已准备好的不可变传输包,不解压、不重新读取远端源文件。

func (s *Store) Link(artifact Artifact, baseURL string) (string, error)

func (*Store) Open

func (s *Store) Open(name, downloadName, signature string, head bool) (*Lease, error)

func (*Store) Sweep

func (s *Store) Sweep() error

Sweep 只处理受控名称的普通文件;活动写入或领取不会被后台清理。

Jump to

Keyboard shortcuts

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