caches

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: BSD-3-Clause Imports: 56 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SuffixAll         = "@GOEDGE_"        // 通用后缀
	SuffixWebP        = "@GOEDGE_WEBP"    // WebP后缀
	SuffixCompression = "@GOEDGE_"        // 压缩后缀 SuffixCompression + Encoding
	SuffixMethod      = "@GOEDGE_"        // 请求方法后缀 SuffixMethod + RequestMethod
	SuffixPartial     = "@GOEDGE_partial" // 分区缓存后缀
)
View Source
const (
	SizeExpiresAt      = 4
	OffsetExpiresAt    = 0
	SizeStatus         = 3
	OffsetStatus       = SizeExpiresAt
	SizeURLLength      = 4
	OffsetURLLength    = OffsetStatus + SizeStatus
	SizeHeaderLength   = 4
	OffsetHeaderLength = OffsetURLLength + SizeURLLength
	SizeBodyLength     = 8
	OffsetBodyLength   = OffsetHeaderLength + SizeHeaderLength

	SizeMeta = SizeExpiresAt + SizeStatus + SizeURLLength + SizeHeaderLength + SizeBodyLength
)
View Source
const (
	FileStorageMaxIgnoreKeys        = 32768        // 最大可忽略的键值数(尺寸过大的键值)
	HotItemSize                     = 1024         // 热点数据数量
	HotItemLifeSeconds       int64  = 3600         // 热点数据生命周期
	FileToMemoryMaxSize             = 32 * sizes.M // 可以从文件写入到内存的最大文件尺寸
	FileTmpSuffix                   = ".tmp"
	DefaultMinDiskFreeSpace  uint64 = 5 << 30 // 当前磁盘最小剩余空间
	DefaultStaleCacheSeconds        = 1200    // 过时缓存留存时间
	HashKeyLength                   = 32
)
View Source
const CountFileDB = 20
View Source
const HashMapSharding = 31

Variables

View Source
var (
	ErrNotFound           = errors.New("cache not found")
	ErrFileIsWriting      = errors.New("the cache file is updating")
	ErrInvalidRange       = errors.New("invalid range")
	ErrEntityTooLarge     = errors.New("entity too large")
	ErrWritingUnavailable = errors.New("writing unavailable")
	ErrWritingQueueFull   = errors.New("writing queue full")
	ErrServerIsBusy       = errors.New("server is busy")
)

常用的几个错误

View Source
var SharedManager = NewManager()

Functions

func CanIgnoreErr

func CanIgnoreErr(err error) bool

CanIgnoreErr 检查错误是否可以忽略

func NewCapacityError

func NewCapacityError(err string) error

func ParseHost added in v0.5.8

func ParseHost(key string) string

func PartialRangesFilePath added in v1.2.9

func PartialRangesFilePath(path string) string

PartialRangesFilePath 获取 ranges 文件路径

Types

type CapacityError

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

CapacityError 容量错误 独立出来是为了可以在有些场合下可以忽略,防止产生没必要的错误提示数量太多

func (*CapacityError) Error

func (this *CapacityError) Error() string

type FileDir added in v0.5.8

type FileDir struct {
	Path     string
	Capacity *shared.SizeCapacity
	IsFull   bool
}

type FileReader

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

func NewFileReader

func NewFileReader(fp *os.File) *FileReader

func (*FileReader) BodySize

func (this *FileReader) BodySize() int64

func (*FileReader) Close

func (this *FileReader) Close() error

func (*FileReader) ContainsRange

func (this *FileReader) ContainsRange(r rangeutils.Range) (r2 rangeutils.Range, ok bool)

ContainsRange 是否包含某些区间内容

func (*FileReader) ExpiresAt

func (this *FileReader) ExpiresAt() int64

func (*FileReader) FP

func (this *FileReader) FP() *os.File

FP 原始的文件句柄

func (*FileReader) HeaderSize

func (this *FileReader) HeaderSize() int64

func (*FileReader) Init

func (this *FileReader) Init() error

func (*FileReader) InitAutoDiscard

func (this *FileReader) InitAutoDiscard(autoDiscard bool) error

func (*FileReader) LastModified

func (this *FileReader) LastModified() int64

func (*FileReader) Read

func (this *FileReader) Read(buf []byte) (n int, err error)

func (*FileReader) ReadBody

func (this *FileReader) ReadBody(buf []byte, callback ReaderFunc) error

func (*FileReader) ReadBodyRange

func (this *FileReader) ReadBodyRange(buf []byte, start int64, end int64, callback ReaderFunc) error

func (*FileReader) ReadHeader

func (this *FileReader) ReadHeader(buf []byte, callback ReaderFunc) error

func (*FileReader) Status

func (this *FileReader) Status() int

func (*FileReader) TypeName

func (this *FileReader) TypeName() string

type FileStorage

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

FileStorage 文件缓存

文件结构:
 [expires time] | [ status ] | [url length] | [header length] | [body length] | [url] [header data] [body data]

func NewFileStorage

func NewFileStorage(policy *serverconfigs.HTTPCachePolicy) *FileStorage

func (*FileStorage) AddToList

func (this *FileStorage) AddToList(item *Item)

AddToList 添加到List

func (*FileStorage) CanSendfile

func (this *FileStorage) CanSendfile() bool

CanSendfile 是否支持Sendfile

func (*FileStorage) CanUpdatePolicy

func (this *FileStorage) CanUpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy) bool

CanUpdatePolicy 检查策略是否可以更新

func (*FileStorage) CleanAll

func (this *FileStorage) CleanAll() error

CleanAll 清除所有的缓存

func (*FileStorage) Delete

func (this *FileStorage) Delete(key string) error

Delete 删除某个键值对应的缓存

func (*FileStorage) IgnoreKey

func (this *FileStorage) IgnoreKey(key string, maxSize int64)

IgnoreKey 忽略某个Key,即不缓存某个Key

func (*FileStorage) Init

func (this *FileStorage) Init() error

Init 初始化

func (*FileStorage) OpenFlushWriter

func (this *FileStorage) OpenFlushWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64) (Writer, error)

OpenFlushWriter 打开从其他媒介直接刷入的写入器

func (*FileStorage) OpenReader

func (this *FileStorage) OpenReader(key string, useStale bool, isPartial bool) (Reader, error)

func (*FileStorage) OpenWriter

func (this *FileStorage) OpenWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64, maxSize int64, isPartial bool) (Writer, error)

OpenWriter 打开缓存文件等待写入

func (*FileStorage) Policy

func (this *FileStorage) Policy() *serverconfigs.HTTPCachePolicy

Policy 获取当前的Policy

func (*FileStorage) Purge

func (this *FileStorage) Purge(keys []string, urlType string) error

Purge 清理过期的缓存

func (*FileStorage) ScanGarbageCaches added in v1.2.9

func (this *FileStorage) ScanGarbageCaches(fileCallback func(path string) error) error

ScanGarbageCaches 清理目录中“失联”的缓存文件 “失联”为不在HashMap中的文件

func (*FileStorage) Stat

func (this *FileStorage) Stat() (*Stat, error)

Stat 统计

func (*FileStorage) Stop

func (this *FileStorage) Stop()

Stop 停止

func (*FileStorage) TotalDiskSize

func (this *FileStorage) TotalDiskSize() int64

TotalDiskSize 消耗的磁盘尺寸

func (*FileStorage) TotalMemorySize

func (this *FileStorage) TotalMemorySize() int64

TotalMemorySize 内存尺寸

func (*FileStorage) UpdatePolicy

func (this *FileStorage) UpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy)

UpdatePolicy 修改策略

type FileWriter

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

func NewFileWriter

func NewFileWriter(storage StorageInterface, rawWriter *os.File, key string, expiredAt int64, metaHeaderSize int, metaBodySize int64, maxSize int64, endFunc func()) *FileWriter

func (*FileWriter) BodySize

func (this *FileWriter) BodySize() int64

func (*FileWriter) Close

func (this *FileWriter) Close() error

Close 关闭

func (*FileWriter) Discard

func (this *FileWriter) Discard() error

Discard 丢弃

func (*FileWriter) ExpiredAt

func (this *FileWriter) ExpiredAt() int64

func (*FileWriter) HeaderSize

func (this *FileWriter) HeaderSize() int64

func (*FileWriter) ItemType

func (this *FileWriter) ItemType() ItemType

ItemType 获取内容类型

func (*FileWriter) Key

func (this *FileWriter) Key() string

func (*FileWriter) Write

func (this *FileWriter) Write(data []byte) (n int, err error)

Write 写入数据

func (*FileWriter) WriteAt

func (this *FileWriter) WriteAt(offset int64, data []byte) error

WriteAt 在指定位置写入数据

func (*FileWriter) WriteBodyLength

func (this *FileWriter) WriteBodyLength(bodyLength int64) error

WriteBodyLength 写入Body长度数据

func (*FileWriter) WriteHeader

func (this *FileWriter) WriteHeader(data []byte) (n int, err error)

WriteHeader 写入数据

func (*FileWriter) WriteHeaderLength

func (this *FileWriter) WriteHeaderLength(headerLength int) error

WriteHeaderLength 写入Header长度数据

type HotItem

type HotItem struct {
	Key  string
	Hits uint32
}

type Item

type Item struct {
	Type       ItemType `json:"-"`
	Key        string   `json:"1,omitempty"`
	ExpiresAt  int64    `json:"2,omitempty"`
	StaleAt    int64    `json:"3,omitempty"`
	HeaderSize int64    `json:"-"`
	BodySize   int64    `json:"4,omitempty"`
	MetaSize   int64    `json:"-"`
	Host       string   `json:"-"`           // 主机名
	ServerId   int64    `json:"5,omitempty"` // 服务ID
	Week       int32    `json:"-"`
	CreatedAt  int64    `json:"6,omitempty"`
}

func (*Item) IsExpired

func (this *Item) IsExpired() bool

func (*Item) RequestURI added in v0.5.8

func (this *Item) RequestURI() string

func (*Item) Size

func (this *Item) Size() int64

func (*Item) TotalSize

func (this *Item) TotalSize() int64

type ItemKVEncoder added in v1.3.4

type ItemKVEncoder[T interface{ *Item }] struct {
}

ItemKVEncoder item encoder

func NewItemKVEncoder added in v1.3.4

func NewItemKVEncoder[T interface{ *Item }]() *ItemKVEncoder[T]

func (*ItemKVEncoder[T]) Decode added in v1.3.4

func (this *ItemKVEncoder[T]) Decode(valueBytes []byte) (value T, err error)

func (*ItemKVEncoder[T]) Encode added in v1.3.4

func (this *ItemKVEncoder[T]) Encode(value T) ([]byte, error)

func (*ItemKVEncoder[T]) EncodeField added in v1.3.4

func (this *ItemKVEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error)

type ItemType

type ItemType = int
const (
	ItemTypeFile   ItemType = 1
	ItemTypeMemory ItemType = 2
)

type KVFileList added in v1.3.4

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

func NewKVFileList added in v1.3.4

func NewKVFileList(dir string) *KVFileList

func (*KVFileList) Add added in v1.3.4

func (this *KVFileList) Add(hash string, item *Item) error

Add 添加内容

func (*KVFileList) CleanAll added in v1.3.4

func (this *KVFileList) CleanAll() error

CleanAll 清除所有缓存

func (*KVFileList) CleanMatchKey added in v1.3.4

func (this *KVFileList) CleanMatchKey(key string) error

CleanMatchKey 清除通配符匹配的Key

func (*KVFileList) CleanMatchPrefix added in v1.3.4

func (this *KVFileList) CleanMatchPrefix(prefix string) error

CleanMatchPrefix 清除通配符匹配的前缀

func (*KVFileList) CleanPrefix added in v1.3.4

func (this *KVFileList) CleanPrefix(prefix string) error

CleanPrefix 清除某个前缀的缓存

func (*KVFileList) Close added in v1.3.4

func (this *KVFileList) Close() error

Close 关闭

func (*KVFileList) Count added in v1.3.4

func (this *KVFileList) Count() (int64, error)

Count 总数量

func (*KVFileList) Exist added in v1.3.4

func (this *KVFileList) Exist(hash string) (bool, error)

Exist 检查内容是否存在

func (*KVFileList) ExistQuick added in v1.3.4

func (this *KVFileList) ExistQuick(hash string) (bool, error)

ExistQuick 快速检查内容是否存在

func (*KVFileList) IncreaseHit added in v1.3.4

func (this *KVFileList) IncreaseHit(hash string) error

IncreaseHit 增加点击量

func (*KVFileList) Init added in v1.3.4

func (this *KVFileList) Init() error

Init 初始化

func (*KVFileList) OnAdd added in v1.3.4

func (this *KVFileList) OnAdd(fn func(item *Item))

OnAdd 添加事件

func (*KVFileList) OnRemove added in v1.3.4

func (this *KVFileList) OnRemove(fn func(item *Item))

OnRemove 删除事件

func (*KVFileList) Purge added in v1.3.4

func (this *KVFileList) Purge(count int, callback func(hash string) error) (int, error)

Purge 清理过期数据

func (*KVFileList) PurgeLFU added in v1.3.4

func (this *KVFileList) PurgeLFU(count int, callback func(hash string) error) error

PurgeLFU 清理LFU数据

func (*KVFileList) Remove added in v1.3.4

func (this *KVFileList) Remove(hash string) error

Remove 删除内容

func (*KVFileList) Reset added in v1.3.4

func (this *KVFileList) Reset() error

Reset 重置数据

func (*KVFileList) Stat added in v1.3.4

func (this *KVFileList) Stat(check func(hash string) bool) (*Stat, error)

Stat 统计

func (*KVFileList) TestInspect added in v1.3.4

func (this *KVFileList) TestInspect(t *testing.T) error

type KVListFileStore added in v1.3.4

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

func NewKVListFileStore added in v1.3.4

func NewKVListFileStore(path string) *KVListFileStore

func (*KVListFileStore) AddItem added in v1.3.4

func (this *KVListFileStore) AddItem(hash string, item *Item) error

func (*KVListFileStore) CleanItemsWithPrefix added in v1.3.4

func (this *KVListFileStore) CleanItemsWithPrefix(prefix string) error

func (*KVListFileStore) CleanItemsWithWildcardKey added in v1.3.4

func (this *KVListFileStore) CleanItemsWithWildcardKey(key string) error

func (*KVListFileStore) CleanItemsWithWildcardPrefix added in v1.3.4

func (this *KVListFileStore) CleanItemsWithWildcardPrefix(prefix string) error

func (*KVListFileStore) Close added in v1.3.4

func (this *KVListFileStore) Close() error

func (*KVListFileStore) CountItems added in v1.3.4

func (this *KVListFileStore) CountItems() (int64, error)

func (*KVListFileStore) ExistItem added in v1.3.4

func (this *KVListFileStore) ExistItem(hash string) (bool, error)

func (*KVListFileStore) ExistQuickItem added in v1.3.4

func (this *KVListFileStore) ExistQuickItem(hash string) (bool, error)

func (*KVListFileStore) Open added in v1.3.4

func (this *KVListFileStore) Open() error

func (*KVListFileStore) Path added in v1.3.4

func (this *KVListFileStore) Path() string

func (*KVListFileStore) PurgeItems added in v1.3.4

func (this *KVListFileStore) PurgeItems(count int, callback func(hash string) error) (int, error)

func (*KVListFileStore) PurgeLFUItems added in v1.3.4

func (this *KVListFileStore) PurgeLFUItems(count int, callback func(hash string) error) error

func (*KVListFileStore) RemoveAllItems added in v1.3.4

func (this *KVListFileStore) RemoveAllItems() error

func (*KVListFileStore) RemoveItem added in v1.3.4

func (this *KVListFileStore) RemoveItem(hash string) error

func (*KVListFileStore) StatItems added in v1.3.4

func (this *KVListFileStore) StatItems() (*Stat, error)

func (*KVListFileStore) TestInspect added in v1.3.4

func (this *KVListFileStore) TestInspect(t *testing.T) error

type ListInterface

type ListInterface interface {
	// Init 初始化
	Init() error

	// Reset 重置数据
	Reset() error

	// Add 添加内容
	Add(hash string, item *Item) error

	// Exist 检查内容是否存在
	Exist(hash string) (bool, error)

	// CleanPrefix 清除某个前缀的缓存
	CleanPrefix(prefix string) error

	// CleanMatchKey 清除通配符匹配的Key
	CleanMatchKey(key string) error

	// CleanMatchPrefix 清除通配符匹配的前缀
	CleanMatchPrefix(prefix string) error

	// Remove 删除内容
	Remove(hash string) error

	// Purge 清理过期数据
	Purge(count int, callback func(hash string) error) (int, error)

	// PurgeLFU 清理LFU数据
	PurgeLFU(count int, callback func(hash string) error) error

	// CleanAll 清除所有缓存
	CleanAll() error

	// Stat 统计
	Stat(check func(hash string) bool) (*Stat, error)

	// Count 总数量
	Count() (int64, error)

	// OnAdd 添加事件
	OnAdd(f func(item *Item))

	// OnRemove 删除事件
	OnRemove(f func(item *Item))

	// Close 关闭
	Close() error

	// IncreaseHit 增加点击量
	IncreaseHit(hash string) error
}

func NewMemoryList

func NewMemoryList() ListInterface

func NewSQLiteFileList added in v1.3.4

func NewSQLiteFileList(dir string) ListInterface

type Manager

type Manager struct {
	// 全局配置
	MaxDiskCapacity   *shared.SizeCapacity
	MainDiskDir       string
	SubDiskDirs       []*serverconfigs.CacheDir
	MaxMemoryCapacity *shared.SizeCapacity

	CountFileStorages   int
	CountMemoryStorages int
	// contains filtered or unexported fields
}

Manager 缓存策略管理器

func NewManager

func NewManager() *Manager

NewManager 获取管理器对象

func (*Manager) FindAllCachePaths

func (this *Manager) FindAllCachePaths() []string

FindAllCachePaths 所有缓存路径

func (*Manager) FindAllStorages

func (this *Manager) FindAllStorages() []StorageInterface

FindAllStorages 读取所有缓存存储

func (*Manager) FindPolicy

func (this *Manager) FindPolicy(policyId int64) *serverconfigs.HTTPCachePolicy

FindPolicy 获取Policy信息

func (*Manager) FindStorageWithPolicy

func (this *Manager) FindStorageWithPolicy(policyId int64) StorageInterface

FindStorageWithPolicy 根据策略ID查找存储

func (*Manager) MaxSystemMemoryBytesPerStorage added in v1.3.0

func (this *Manager) MaxSystemMemoryBytesPerStorage() int64

MaxSystemMemoryBytesPerStorage 计算单个策略能使用的系统最大内存

func (*Manager) NewStorageWithPolicy

func (this *Manager) NewStorageWithPolicy(policy *serverconfigs.HTTPCachePolicy) StorageInterface

NewStorageWithPolicy 根据策略获取存储对象

func (*Manager) ScanGarbageCaches added in v1.2.9

func (this *Manager) ScanGarbageCaches(callback func(path string) error) error

ScanGarbageCaches 清理目录中“失联”的缓存文件

func (*Manager) StorageMap added in v1.3.0

func (this *Manager) StorageMap() map[int64]StorageInterface

StorageMap 获取已有的存储对象

func (*Manager) TotalDiskSize

func (this *Manager) TotalDiskSize() int64

TotalDiskSize 消耗的磁盘尺寸

func (*Manager) TotalMemorySize

func (this *Manager) TotalMemorySize() int64

TotalMemorySize 消耗的内存尺寸

func (*Manager) UpdatePolicies

func (this *Manager) UpdatePolicies(newPolicies []*serverconfigs.HTTPCachePolicy)

UpdatePolicies 重新设置策略

type MemoryFragmentPool added in v1.2.10

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

MemoryFragmentPool memory fragments management

var SharedFragmentMemoryPool *MemoryFragmentPool

func NewMemoryFragmentPool added in v1.2.10

func NewMemoryFragmentPool() *MemoryFragmentPool

NewMemoryFragmentPool create new fragment memory pool

func (*MemoryFragmentPool) GC added in v1.2.10

func (this *MemoryFragmentPool) GC()

GC fully GC

func (*MemoryFragmentPool) GCNextBucket added in v1.2.10

func (this *MemoryFragmentPool) GCNextBucket() (isEmpty bool)

GCNextBucket gc one bucket

func (*MemoryFragmentPool) Get added in v1.2.10

func (this *MemoryFragmentPool) Get(expectSize int64) (resultBytes []byte, ok bool)

Get try to get a bytes object

func (*MemoryFragmentPool) IncreaseNew added in v1.2.10

func (this *MemoryFragmentPool) IncreaseNew()

func (*MemoryFragmentPool) Len added in v1.2.10

func (this *MemoryFragmentPool) Len() int

func (*MemoryFragmentPool) Put added in v1.2.10

func (this *MemoryFragmentPool) Put(data []byte) (ok bool)

Put a bytes object to specified bucket

func (*MemoryFragmentPool) SetCapacity added in v1.2.10

func (this *MemoryFragmentPool) SetCapacity(capacity int64)

func (*MemoryFragmentPool) TotalSize added in v1.2.10

func (this *MemoryFragmentPool) TotalSize() int64

type MemoryFragmentPoolItem added in v1.2.10

type MemoryFragmentPoolItem struct {
	Bytes []byte

	Refs int32
	// contains filtered or unexported fields
}

func (*MemoryFragmentPoolItem) IsAvailable added in v1.2.10

func (this *MemoryFragmentPoolItem) IsAvailable() bool

func (*MemoryFragmentPoolItem) IsExpired added in v1.2.10

func (this *MemoryFragmentPoolItem) IsExpired() bool

func (*MemoryFragmentPoolItem) Reset added in v1.2.10

func (this *MemoryFragmentPoolItem) Reset()

type MemoryItem

type MemoryItem struct {
	ExpiresAt   int64
	HeaderValue []byte
	BodyValue   []byte
	Status      int
	IsDone      bool
	ModifiedAt  int64

	IsPrepared  bool
	WriteOffset int64
	// contains filtered or unexported fields
}

func (*MemoryItem) IsExpired

func (this *MemoryItem) IsExpired() bool

type MemoryList

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

MemoryList 内存缓存列表管理

func (*MemoryList) Add

func (this *MemoryList) Add(hash string, item *Item) error

func (*MemoryList) CleanAll

func (this *MemoryList) CleanAll() error

func (*MemoryList) CleanMatchKey added in v0.5.8

func (this *MemoryList) CleanMatchKey(key string) error

CleanMatchKey 清理通配符匹配的缓存数据,类似于 https://*.example.com/hello

func (*MemoryList) CleanMatchPrefix added in v0.5.8

func (this *MemoryList) CleanMatchPrefix(prefix string) error

CleanMatchPrefix 清理通配符匹配的缓存数据,类似于 https://*.example.com/prefix/

func (*MemoryList) CleanPrefix

func (this *MemoryList) CleanPrefix(prefix string) error

CleanPrefix 根据前缀进行清除

func (*MemoryList) Close

func (this *MemoryList) Close() error

func (*MemoryList) Count

func (this *MemoryList) Count() (int64, error)

Count 总数量

func (*MemoryList) Exist

func (this *MemoryList) Exist(hash string) (bool, error)

func (*MemoryList) IncreaseHit

func (this *MemoryList) IncreaseHit(hash string) error

IncreaseHit 增加点击量

func (*MemoryList) Init

func (this *MemoryList) Init() error

func (*MemoryList) ItemMaps added in v1.3.3

func (this *MemoryList) ItemMaps() map[string]map[string]*Item

func (*MemoryList) OnAdd

func (this *MemoryList) OnAdd(f func(item *Item))

OnAdd 添加事件

func (*MemoryList) OnRemove

func (this *MemoryList) OnRemove(f func(item *Item))

OnRemove 删除事件

func (*MemoryList) Prefixes added in v1.3.3

func (this *MemoryList) Prefixes() []string

func (*MemoryList) Print added in v1.3.3

func (this *MemoryList) Print(t *testing.T)

func (*MemoryList) Purge

func (this *MemoryList) Purge(count int, callback func(hash string) error) (int, error)

Purge 清理过期的缓存 count 每次遍历的最大数量,控制此数字可以保证每次清理的时候不用花太多时间 callback 每次发现过期key的调用

func (*MemoryList) PurgeIndex added in v1.3.3

func (this *MemoryList) PurgeIndex() int

func (*MemoryList) PurgeLFU

func (this *MemoryList) PurgeLFU(count int, callback func(hash string) error) error

func (*MemoryList) Remove

func (this *MemoryList) Remove(hash string) error

func (*MemoryList) Reset

func (this *MemoryList) Reset() error

func (*MemoryList) Stat

func (this *MemoryList) Stat(check func(hash string) bool) (*Stat, error)

type MemoryReader

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

func NewMemoryReader

func NewMemoryReader(item *MemoryItem) *MemoryReader

func (*MemoryReader) BodySize

func (this *MemoryReader) BodySize() int64

func (*MemoryReader) Close

func (this *MemoryReader) Close() error

func (*MemoryReader) ContainsRange

func (this *MemoryReader) ContainsRange(r rangeutils.Range) (r2 rangeutils.Range, ok bool)

ContainsRange 是否包含某些区间内容

func (*MemoryReader) ExpiresAt

func (this *MemoryReader) ExpiresAt() int64

func (*MemoryReader) HeaderSize

func (this *MemoryReader) HeaderSize() int64

func (*MemoryReader) Init

func (this *MemoryReader) Init() error

func (*MemoryReader) LastModified

func (this *MemoryReader) LastModified() int64

func (*MemoryReader) Read

func (this *MemoryReader) Read(buf []byte) (n int, err error)

func (*MemoryReader) ReadBody

func (this *MemoryReader) ReadBody(buf []byte, callback ReaderFunc) error

func (*MemoryReader) ReadBodyRange

func (this *MemoryReader) ReadBodyRange(buf []byte, start int64, end int64, callback ReaderFunc) error

func (*MemoryReader) ReadHeader

func (this *MemoryReader) ReadHeader(buf []byte, callback ReaderFunc) error

func (*MemoryReader) Status

func (this *MemoryReader) Status() int

func (*MemoryReader) TypeName

func (this *MemoryReader) TypeName() string

type MemoryStorage

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

func NewMemoryStorage

func NewMemoryStorage(policy *serverconfigs.HTTPCachePolicy, parentStorage StorageInterface) *MemoryStorage

func (*MemoryStorage) AddToList

func (this *MemoryStorage) AddToList(item *Item)

AddToList 将缓存添加到列表

func (*MemoryStorage) CanSendfile

func (this *MemoryStorage) CanSendfile() bool

CanSendfile 是否支持Sendfile

func (*MemoryStorage) CanUpdatePolicy

func (this *MemoryStorage) CanUpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy) bool

CanUpdatePolicy 检查策略是否可以更新

func (*MemoryStorage) CleanAll

func (this *MemoryStorage) CleanAll() error

CleanAll 清除所有缓存

func (*MemoryStorage) Delete

func (this *MemoryStorage) Delete(key string) error

Delete 删除某个键值对应的缓存

func (*MemoryStorage) HasFreeSpaceForHotItems added in v1.2.10

func (this *MemoryStorage) HasFreeSpaceForHotItems() bool

HasFreeSpaceForHotItems 是否有足够的空间提供给热门内容

func (*MemoryStorage) IgnoreKey

func (this *MemoryStorage) IgnoreKey(key string, maxSize int64)

IgnoreKey 忽略某个Key,即不缓存某个Key

func (*MemoryStorage) Init

func (this *MemoryStorage) Init() error

Init 初始化

func (*MemoryStorage) OpenFlushWriter

func (this *MemoryStorage) OpenFlushWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64) (Writer, error)

OpenFlushWriter 打开从其他媒介直接刷入的写入器

func (*MemoryStorage) OpenReader

func (this *MemoryStorage) OpenReader(key string, useStale bool, isPartial bool) (Reader, error)

OpenReader 读取缓存

func (*MemoryStorage) OpenWriter

func (this *MemoryStorage) OpenWriter(key string, expiredAt int64, status int, headerSize int, bodySize int64, maxSize int64, isPartial bool) (Writer, error)

OpenWriter 打开缓存写入器等待写入

func (*MemoryStorage) Policy

Policy 获取当前存储的Policy

func (*MemoryStorage) Purge

func (this *MemoryStorage) Purge(keys []string, urlType string) error

Purge 批量删除缓存

func (*MemoryStorage) Stat

func (this *MemoryStorage) Stat() (*Stat, error)

Stat 统计缓存

func (*MemoryStorage) Stop

func (this *MemoryStorage) Stop()

Stop 停止缓存策略

func (*MemoryStorage) TotalDiskSize

func (this *MemoryStorage) TotalDiskSize() int64

TotalDiskSize 消耗的磁盘尺寸

func (*MemoryStorage) TotalMemorySize

func (this *MemoryStorage) TotalMemorySize() int64

TotalMemorySize 内存尺寸

func (*MemoryStorage) UpdatePolicy

func (this *MemoryStorage) UpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy)

UpdatePolicy 修改策略

type MemoryWriter

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

func NewMemoryWriter

func NewMemoryWriter(memoryStorage *MemoryStorage, key string, expiredAt int64, status int, isDirty bool, expectedBodySize int64, maxSize int64, endFunc func(valueItem *MemoryItem)) *MemoryWriter

func (*MemoryWriter) BodySize

func (this *MemoryWriter) BodySize() int64

BodySize 主体内容尺寸

func (*MemoryWriter) Close

func (this *MemoryWriter) Close() error

Close 关闭

func (*MemoryWriter) Discard

func (this *MemoryWriter) Discard() error

Discard 丢弃

func (*MemoryWriter) ExpiredAt

func (this *MemoryWriter) ExpiredAt() int64

ExpiredAt 过期时间

func (*MemoryWriter) HeaderSize

func (this *MemoryWriter) HeaderSize() int64

HeaderSize 数据尺寸

func (*MemoryWriter) ItemType

func (this *MemoryWriter) ItemType() ItemType

ItemType 内容类型

func (*MemoryWriter) Key

func (this *MemoryWriter) Key() string

Key 获取Key

func (*MemoryWriter) Write

func (this *MemoryWriter) Write(data []byte) (n int, err error)

Write 写入数据

func (*MemoryWriter) WriteAt

func (this *MemoryWriter) WriteAt(offset int64, b []byte) error

WriteAt 在指定位置写入数据

func (*MemoryWriter) WriteHeader

func (this *MemoryWriter) WriteHeader(data []byte) (n int, err error)

WriteHeader 写入数据

type OpenFile

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

func NewOpenFile

func NewOpenFile(fp *os.File, meta []byte, header []byte, version int64, size int64) *OpenFile

func (*OpenFile) Close

func (this *OpenFile) Close() error

func (*OpenFile) SeekStart

func (this *OpenFile) SeekStart() error

type OpenFileCache

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

func NewOpenFileCache

func NewOpenFileCache(maxCount int) (*OpenFileCache, error)

func (*OpenFileCache) Close

func (this *OpenFileCache) Close(filename string)

func (*OpenFileCache) CloseAll

func (this *OpenFileCache) CloseAll()

func (*OpenFileCache) Debug

func (this *OpenFileCache) Debug()

func (*OpenFileCache) Get

func (this *OpenFileCache) Get(filename string) *OpenFile

func (*OpenFileCache) Put

func (this *OpenFileCache) Put(filename string, file *OpenFile)

func (*OpenFileCache) SetCapacity added in v1.2.10

func (this *OpenFileCache) SetCapacity(capacityBytes int64)

type OpenFilePool

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

func NewOpenFilePool

func NewOpenFilePool(filename string) *OpenFilePool

func (*OpenFilePool) Close

func (this *OpenFilePool) Close()

func (*OpenFilePool) Filename

func (this *OpenFilePool) Filename() string

func (*OpenFilePool) Get

func (this *OpenFilePool) Get() (resultFile *OpenFile, consumed bool, consumedSize int64)

func (*OpenFilePool) Len

func (this *OpenFilePool) Len() int

func (*OpenFilePool) Put

func (this *OpenFilePool) Put(file *OpenFile) bool

func (*OpenFilePool) SetClosing added in v0.6.0

func (this *OpenFilePool) SetClosing()

func (*OpenFilePool) TotalSize added in v1.2.10

func (this *OpenFilePool) TotalSize() int64

type PartialFileReader

type PartialFileReader struct {
	*FileReader
	// contains filtered or unexported fields
}

func NewPartialFileReader

func NewPartialFileReader(fp *os.File) *PartialFileReader

func (*PartialFileReader) ContainsRange

func (this *PartialFileReader) ContainsRange(r rangeutils.Range) (r2 rangeutils.Range, ok bool)

ContainsRange 是否包含某些区间内容 这里的 r 是已经经过格式化的

func (*PartialFileReader) Init

func (this *PartialFileReader) Init() error

func (*PartialFileReader) InitAutoDiscard

func (this *PartialFileReader) InitAutoDiscard(autoDiscard bool) error

func (*PartialFileReader) MaxLength

func (this *PartialFileReader) MaxLength() int64

MaxLength 获取区间最大长度

func (*PartialFileReader) Ranges added in v0.5.8

func (this *PartialFileReader) Ranges() *PartialRanges

type PartialFileWriter

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

func NewPartialFileWriter

func NewPartialFileWriter(rawWriter *os.File, key string, expiredAt int64, metaHeaderSize int, metaBodySize int64, isNew bool, isPartial bool, bodyOffset int64, ranges *PartialRanges, endFunc func()) *PartialFileWriter

func (*PartialFileWriter) AppendHeader

func (this *PartialFileWriter) AppendHeader(data []byte) error

func (*PartialFileWriter) BodySize

func (this *PartialFileWriter) BodySize() int64

func (*PartialFileWriter) Close

func (this *PartialFileWriter) Close() error

Close 关闭

func (*PartialFileWriter) Discard

func (this *PartialFileWriter) Discard() error

Discard 丢弃

func (*PartialFileWriter) ExpiredAt

func (this *PartialFileWriter) ExpiredAt() int64

func (*PartialFileWriter) HeaderSize

func (this *PartialFileWriter) HeaderSize() int64

func (*PartialFileWriter) IsNew

func (this *PartialFileWriter) IsNew() bool

func (*PartialFileWriter) ItemType

func (this *PartialFileWriter) ItemType() ItemType

ItemType 获取内容类型

func (*PartialFileWriter) Key

func (this *PartialFileWriter) Key() string

func (*PartialFileWriter) SetBodyLength

func (this *PartialFileWriter) SetBodyLength(bodyLength int64)

SetBodyLength 设置内容总长度

func (*PartialFileWriter) Write

func (this *PartialFileWriter) Write(data []byte) (n int, err error)

Write 写入数据

func (*PartialFileWriter) WriteAt

func (this *PartialFileWriter) WriteAt(offset int64, data []byte) error

WriteAt 在指定位置写入数据

func (*PartialFileWriter) WriteBodyLength

func (this *PartialFileWriter) WriteBodyLength(bodyLength int64) error

WriteBodyLength 写入Body长度数据

func (*PartialFileWriter) WriteHeader

func (this *PartialFileWriter) WriteHeader(data []byte) (n int, err error)

WriteHeader 写入数据

func (*PartialFileWriter) WriteHeaderLength

func (this *PartialFileWriter) WriteHeaderLength(headerLength int) error

WriteHeaderLength 写入Header长度数据

type PartialRanges

type PartialRanges struct {
	Version  int        `json:"version"`  // 版本号
	Ranges   [][2]int64 `json:"ranges"`   // 范围
	BodySize int64      `json:"bodySize"` // 总长度
}

PartialRanges 内容分区范围定义

func NewPartialRanges

func NewPartialRanges(expiresAt int64) *PartialRanges

NewPartialRanges 获取新对象

func NewPartialRangesFromData added in v0.5.8

func NewPartialRangesFromData(data []byte) (*PartialRanges, error)

NewPartialRangesFromData 从数据中解析范围

func NewPartialRangesFromFile

func NewPartialRangesFromFile(path string) (*PartialRanges, error)

NewPartialRangesFromFile 从文件中加载范围信息

func NewPartialRangesFromJSON

func NewPartialRangesFromJSON(data []byte) (*PartialRanges, error)

NewPartialRangesFromJSON 从JSON中解析范围

func (*PartialRanges) Add

func (this *PartialRanges) Add(begin int64, end int64)

Add 添加新范围

func (*PartialRanges) Bytes added in v0.5.8

func (this *PartialRanges) Bytes() []byte

Bytes 将内容转换为字节

func (*PartialRanges) Contains

func (this *PartialRanges) Contains(begin int64, end int64) bool

Contains 检查是否包含某个范围

func (*PartialRanges) Max

func (this *PartialRanges) Max() int64

Max 获取最大位置

func (*PartialRanges) Nearest

func (this *PartialRanges) Nearest(begin int64, end int64) (r [2]int64, ok bool)

Nearest 查找最近的某个范围

func (*PartialRanges) Reset added in v0.5.8

func (this *PartialRanges) Reset()

Reset 重置范围信息

func (*PartialRanges) String added in v0.5.8

func (this *PartialRanges) String() string

转换为字符串

func (*PartialRanges) WriteToFile

func (this *PartialRanges) WriteToFile(path string) error

WriteToFile 写入到文件中

type Reader

type Reader interface {
	// Init 初始化
	Init() error

	// TypeName 类型名称
	TypeName() string

	// ExpiresAt 过期时间
	ExpiresAt() int64

	// Status 状态码
	Status() int

	// LastModified 最后修改时间
	LastModified() int64

	// ReadHeader 读取Header
	ReadHeader(buf []byte, callback ReaderFunc) error

	// ReadBody 读取Body
	ReadBody(buf []byte, callback ReaderFunc) error

	// Read 实现io.Reader接口
	Read(buf []byte) (int, error)

	// ReadBodyRange 读取某个范围内的Body
	ReadBodyRange(buf []byte, start int64, end int64, callback ReaderFunc) error

	// HeaderSize Header Size
	HeaderSize() int64

	// BodySize Body Size
	BodySize() int64

	// ContainsRange 是否包含某个区间内容
	ContainsRange(r rangeutils.Range) (r2 rangeutils.Range, ok bool)

	// Close 关闭
	Close() error
}

type ReaderFunc

type ReaderFunc func(n int) (goNext bool, err error)

type SQLiteFileList added in v1.3.4

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

SQLiteFileList 文件缓存列表管理

func (*SQLiteFileList) Add added in v1.3.4

func (this *SQLiteFileList) Add(hash string, item *Item) error

func (*SQLiteFileList) CleanAll added in v1.3.4

func (this *SQLiteFileList) CleanAll() error

func (*SQLiteFileList) CleanMatchKey added in v1.3.4

func (this *SQLiteFileList) CleanMatchKey(key string) error

CleanMatchKey 清理通配符匹配的缓存数据,类似于 https://*.example.com/hello

func (*SQLiteFileList) CleanMatchPrefix added in v1.3.4

func (this *SQLiteFileList) CleanMatchPrefix(prefix string) error

CleanMatchPrefix 清理通配符匹配的缓存数据,类似于 https://*.example.com/prefix/

func (*SQLiteFileList) CleanPrefix added in v1.3.4

func (this *SQLiteFileList) CleanPrefix(prefix string) error

CleanPrefix 清理某个前缀的缓存数据

func (*SQLiteFileList) Close added in v1.3.4

func (this *SQLiteFileList) Close() error

func (*SQLiteFileList) Count added in v1.3.4

func (this *SQLiteFileList) Count() (int64, error)

Count 总数量 常用的方法,所以避免直接查询数据库

func (*SQLiteFileList) Exist added in v1.3.4

func (this *SQLiteFileList) Exist(hash string) (bool, error)

func (*SQLiteFileList) ExistQuick added in v1.3.4

func (this *SQLiteFileList) ExistQuick(hash string) (isReady bool, found bool)

func (*SQLiteFileList) GetDB added in v1.3.4

func (this *SQLiteFileList) GetDB(hash string) *SQLiteFileListDB

func (*SQLiteFileList) GetDBIndex added in v1.3.4

func (this *SQLiteFileList) GetDBIndex(hash string) uint64

func (*SQLiteFileList) HashMapIsLoaded added in v1.3.4

func (this *SQLiteFileList) HashMapIsLoaded() bool

func (*SQLiteFileList) IncreaseHit added in v1.3.4

func (this *SQLiteFileList) IncreaseHit(hash string) error

IncreaseHit 增加点击量

func (*SQLiteFileList) Init added in v1.3.4

func (this *SQLiteFileList) Init() error

func (*SQLiteFileList) OnAdd added in v1.3.4

func (this *SQLiteFileList) OnAdd(f func(item *Item))

OnAdd 添加事件

func (*SQLiteFileList) OnRemove added in v1.3.4

func (this *SQLiteFileList) OnRemove(f func(item *Item))

OnRemove 删除事件

func (*SQLiteFileList) Purge added in v1.3.4

func (this *SQLiteFileList) Purge(count int, callback func(hash string) error) (int, error)

Purge 清理过期的缓存 count 每次遍历的最大数量,控制此数字可以保证每次清理的时候不用花太多时间 callback 每次发现过期key的调用

func (*SQLiteFileList) PurgeLFU added in v1.3.4

func (this *SQLiteFileList) PurgeLFU(count int, callback func(hash string) error) error

func (*SQLiteFileList) Remove added in v1.3.4

func (this *SQLiteFileList) Remove(hash string) error

func (*SQLiteFileList) Reset added in v1.3.4

func (this *SQLiteFileList) Reset() error

func (*SQLiteFileList) SetOldDir added in v1.3.4

func (this *SQLiteFileList) SetOldDir(oldDir string)

func (*SQLiteFileList) Stat added in v1.3.4

func (this *SQLiteFileList) Stat(check func(hash string) bool) (*Stat, error)

func (*SQLiteFileList) UpgradeV3 added in v1.3.4

func (this *SQLiteFileList) UpgradeV3(oldDir string, brokenOnError bool) error

type SQLiteFileListDB added in v1.3.4

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

func NewSQLiteFileListDB added in v1.3.4

func NewSQLiteFileListDB() *SQLiteFileListDB

func (*SQLiteFileListDB) AddSync added in v1.3.4

func (this *SQLiteFileListDB) AddSync(hash string, item *Item) error

func (*SQLiteFileListDB) CleanAll added in v1.3.4

func (this *SQLiteFileListDB) CleanAll() error

func (*SQLiteFileListDB) CleanMatchKey added in v1.3.4

func (this *SQLiteFileListDB) CleanMatchKey(key string) error

func (*SQLiteFileListDB) CleanMatchPrefix added in v1.3.4

func (this *SQLiteFileListDB) CleanMatchPrefix(prefix string) error

func (*SQLiteFileListDB) CleanPrefix added in v1.3.4

func (this *SQLiteFileListDB) CleanPrefix(prefix string) error

func (*SQLiteFileListDB) Close added in v1.3.4

func (this *SQLiteFileListDB) Close() error

func (*SQLiteFileListDB) DeleteSync added in v1.3.4

func (this *SQLiteFileListDB) DeleteSync(hash string) error

func (*SQLiteFileListDB) HashMapIsLoaded added in v1.3.4

func (this *SQLiteFileListDB) HashMapIsLoaded() bool

func (*SQLiteFileListDB) IncreaseHitAsync added in v1.3.4

func (this *SQLiteFileListDB) IncreaseHitAsync(hash string) error

func (*SQLiteFileListDB) Init added in v1.3.4

func (this *SQLiteFileListDB) Init() error

func (*SQLiteFileListDB) IsReady added in v1.3.4

func (this *SQLiteFileListDB) IsReady() bool

func (*SQLiteFileListDB) ListExpiredItems added in v1.3.4

func (this *SQLiteFileListDB) ListExpiredItems(count int) (hashList []string, err error)

func (*SQLiteFileListDB) ListHashes added in v1.3.4

func (this *SQLiteFileListDB) ListHashes(lastId int64) (hashList []string, maxId int64, err error)

func (*SQLiteFileListDB) ListLFUItems added in v1.3.4

func (this *SQLiteFileListDB) ListLFUItems(count int) (hashList []string, err error)

func (*SQLiteFileListDB) Open added in v1.3.4

func (this *SQLiteFileListDB) Open(dbPath string) error

func (*SQLiteFileListDB) Total added in v1.3.4

func (this *SQLiteFileListDB) Total() (int64, error)

func (*SQLiteFileListDB) WrapError added in v1.3.4

func (this *SQLiteFileListDB) WrapError(err error) error

type SQLiteFileListHashMap added in v1.3.4

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

SQLiteFileListHashMap 文件Hash列表

func NewSQLiteFileListHashMap added in v1.3.4

func NewSQLiteFileListHashMap() *SQLiteFileListHashMap

func (*SQLiteFileListHashMap) Add added in v1.3.4

func (this *SQLiteFileListHashMap) Add(hash string)

func (*SQLiteFileListHashMap) AddHashes added in v1.3.4

func (this *SQLiteFileListHashMap) AddHashes(hashes []string)

func (*SQLiteFileListHashMap) Clean added in v1.3.4

func (this *SQLiteFileListHashMap) Clean()

func (*SQLiteFileListHashMap) Delete added in v1.3.4

func (this *SQLiteFileListHashMap) Delete(hash string)

func (*SQLiteFileListHashMap) Exist added in v1.3.4

func (this *SQLiteFileListHashMap) Exist(hash string) bool

func (*SQLiteFileListHashMap) IsReady added in v1.3.4

func (this *SQLiteFileListHashMap) IsReady() bool

func (*SQLiteFileListHashMap) Len added in v1.3.4

func (this *SQLiteFileListHashMap) Len() int

func (*SQLiteFileListHashMap) Load added in v1.3.4

func (*SQLiteFileListHashMap) SetIsAvailable added in v1.3.4

func (this *SQLiteFileListHashMap) SetIsAvailable(isAvailable bool)

func (*SQLiteFileListHashMap) SetIsReady added in v1.3.4

func (this *SQLiteFileListHashMap) SetIsReady(isReady bool)

type Stat

type Stat struct {
	Count     int   // 数量
	ValueSize int64 // 值占用的空间
	Size      int64 // 占用的空间尺寸
}

type StorageInterface

type StorageInterface interface {
	// Init 初始化
	Init() error

	// OpenReader 读取缓存
	OpenReader(key string, useStale bool, isPartial bool) (reader Reader, err error)

	// OpenWriter 打开缓存写入器等待写入
	// size 和 maxSize 可能为-1
	OpenWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64, maxSize int64, isPartial bool) (Writer, error)

	// OpenFlushWriter 打开从其他媒介直接刷入的写入器
	OpenFlushWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64) (Writer, error)

	// Delete 删除某个键值对应的缓存
	Delete(key string) error

	// Stat 统计缓存
	Stat() (*Stat, error)

	// TotalDiskSize 消耗的磁盘尺寸
	TotalDiskSize() int64

	// TotalMemorySize 内存尺寸
	TotalMemorySize() int64

	// CleanAll 清除所有缓存
	CleanAll() error

	// Purge 批量删除缓存
	// urlType 值为file|dir
	Purge(keys []string, urlType string) error

	// Stop 停止缓存策略
	Stop()

	// Policy 获取当前存储的Policy
	Policy() *serverconfigs.HTTPCachePolicy

	// UpdatePolicy 修改策略
	UpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy)

	// CanUpdatePolicy 检查策略是否可以更新
	CanUpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy) bool

	// AddToList 将缓存添加到列表
	AddToList(item *Item)

	// IgnoreKey 忽略某个Key,即不缓存某个Key
	IgnoreKey(key string, maxSize int64)

	// CanSendfile 是否支持Sendfile
	CanSendfile() bool
}

StorageInterface 缓存存储接口

type Writer

type Writer interface {
	// WriteHeader 写入Header数据
	WriteHeader(data []byte) (n int, err error)

	// Write 写入Body数据
	Write(data []byte) (n int, err error)

	// WriteAt 在指定位置写入数据
	WriteAt(offset int64, data []byte) error

	// HeaderSize 写入的Header数据大小
	HeaderSize() int64

	// BodySize 写入的Body数据大小
	BodySize() int64

	// Close 关闭
	Close() error

	// Discard 丢弃
	Discard() error

	// Key Key
	Key() string

	// ExpiredAt 过期时间
	ExpiredAt() int64

	// ItemType 内容类型
	ItemType() ItemType
}

Writer 缓存内容写入接口

Jump to

Keyboard shortcuts

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