Documentation ¶
Index ¶
- Constants
- Variables
- func CanIgnoreErr(err error) bool
- func IsBusyError(err error) bool
- func IsCapacityError(err error) bool
- func NewCapacityError(err string) error
- func ParseHost(key string) string
- func PartialRangesFilePath(path string) string
- type BaseReader
- type CapacityError
- type FileDir
- type FileReader
- func (this *FileReader) BodySize() int64
- func (this *FileReader) Close() error
- func (this *FileReader) ContainsRange(r rangeutils.Range) (r2 rangeutils.Range, ok bool)
- func (this *FileReader) ExpiresAt() int64
- func (this *FileReader) FP() *os.File
- func (this *FileReader) HeaderSize() int64
- func (this *FileReader) Init() error
- func (this *FileReader) InitAutoDiscard(autoDiscard bool) error
- func (this *FileReader) LastModified() int64
- func (this *FileReader) Read(buf []byte) (n int, err error)
- func (this *FileReader) ReadBody(buf []byte, callback ReaderFunc) error
- func (this *FileReader) ReadBodyRange(buf []byte, start int64, end int64, callback ReaderFunc) error
- func (this *FileReader) ReadHeader(buf []byte, callback ReaderFunc) error
- func (this *FileReader) Status() int
- func (this *FileReader) TypeName() string
- type FileStorage
- func (this *FileStorage) AddToList(item *Item)
- func (this *FileStorage) CanSendfile() bool
- func (this *FileStorage) CanUpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy) bool
- func (this *FileStorage) CleanAll() error
- func (this *FileStorage) Delete(key string) error
- func (this *FileStorage) IgnoreKey(key string, maxSize int64)
- func (this *FileStorage) Init() error
- func (this *FileStorage) OpenFlushWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64) (Writer, error)
- func (this *FileStorage) OpenReader(key string, useStale bool, isPartial bool) (Reader, error)
- func (this *FileStorage) OpenWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64, ...) (Writer, error)
- func (this *FileStorage) Options() *serverconfigs.HTTPFileCacheStorage
- func (this *FileStorage) Policy() *serverconfigs.HTTPCachePolicy
- func (this *FileStorage) Purge(keys []string, urlType string) error
- func (this *FileStorage) ScanGarbageCaches(fileCallback func(path string) error) error
- func (this *FileStorage) Stat() (*Stat, error)
- func (this *FileStorage) Stop()
- func (this *FileStorage) TotalDiskSize() int64
- func (this *FileStorage) TotalMemorySize() int64
- func (this *FileStorage) UpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy)
- type FileWriter
- func (this *FileWriter) BodySize() int64
- func (this *FileWriter) Close() error
- func (this *FileWriter) Discard() error
- func (this *FileWriter) ExpiredAt() int64
- func (this *FileWriter) HeaderSize() int64
- func (this *FileWriter) ItemType() ItemType
- func (this *FileWriter) Key() string
- func (this *FileWriter) Write(data []byte) (n int, err error)
- func (this *FileWriter) WriteAt(offset int64, data []byte) error
- func (this *FileWriter) WriteBodyLength(bodyLength int64) error
- func (this *FileWriter) WriteHeader(data []byte) (n int, err error)
- func (this *FileWriter) WriteHeaderLength(headerLength int) error
- type HotItem
- type Item
- type ItemKVEncoder
- type ItemType
- type KVFileList
- func (this *KVFileList) Add(hash string, item *Item) error
- func (this *KVFileList) CleanAll() error
- func (this *KVFileList) CleanMatchKey(key string) error
- func (this *KVFileList) CleanMatchPrefix(prefix string) error
- func (this *KVFileList) CleanPrefix(prefix string) error
- func (this *KVFileList) Close() error
- func (this *KVFileList) Count() (int64, error)
- func (this *KVFileList) Exist(hash string) (bool, int64, error)
- func (this *KVFileList) ExistQuick(hash string) (bool, error)
- func (this *KVFileList) IncreaseHit(hash string) error
- func (this *KVFileList) Init() error
- func (this *KVFileList) OnAdd(fn func(item *Item))
- func (this *KVFileList) OnRemove(fn func(item *Item))
- func (this *KVFileList) Purge(count int, callback func(hash string) error) (int, error)
- func (this *KVFileList) PurgeLFU(count int, callback func(hash string) error) error
- func (this *KVFileList) Remove(hash string) error
- func (this *KVFileList) Reset() error
- func (this *KVFileList) Stat(check func(hash string) bool) (*Stat, error)
- func (this *KVFileList) TestInspect(t *testing.T) error
- type KVListFileStore
- func (this *KVListFileStore) AddItem(hash string, item *Item) error
- func (this *KVListFileStore) CleanItemsWithPrefix(prefix string) error
- func (this *KVListFileStore) CleanItemsWithWildcardKey(key string) error
- func (this *KVListFileStore) CleanItemsWithWildcardPrefix(prefix string) error
- func (this *KVListFileStore) Close() error
- func (this *KVListFileStore) CountItems() (int64, error)
- func (this *KVListFileStore) ExistItem(hash string) (bool, int64, error)
- func (this *KVListFileStore) ExistQuickItem(hash string) (bool, error)
- func (this *KVListFileStore) Open() error
- func (this *KVListFileStore) Path() string
- func (this *KVListFileStore) PurgeItems(count int, callback func(hash string) error) (int, error)
- func (this *KVListFileStore) PurgeLFUItems(count int, callback func(hash string) error) error
- func (this *KVListFileStore) RemoveAllItems() error
- func (this *KVListFileStore) RemoveItem(hash string) error
- func (this *KVListFileStore) StatItems() (*Stat, error)
- func (this *KVListFileStore) TestInspect(t *testing.T) error
- type ListInterface
- type MMAPFileReader
- type Manager
- func (this *Manager) FindAllCachePaths() []string
- func (this *Manager) FindAllStorages() []StorageInterface
- func (this *Manager) FindPolicy(policyId int64) *serverconfigs.HTTPCachePolicy
- func (this *Manager) FindStorageWithPolicy(policyId int64) StorageInterface
- func (this *Manager) MaxSystemMemoryBytesPerStorage() int64
- func (this *Manager) NewStorageWithPolicy(policy *serverconfigs.HTTPCachePolicy) StorageInterface
- func (this *Manager) ScanGarbageCaches(callback func(path string) error) error
- func (this *Manager) StorageMap() map[int64]StorageInterface
- func (this *Manager) TotalDiskSize() int64
- func (this *Manager) TotalMemorySize() int64
- func (this *Manager) UpdatePolicies(newPolicies []*serverconfigs.HTTPCachePolicy)
- type MemoryItem
- type MemoryList
- func (this *MemoryList) Add(hash string, item *Item) error
- func (this *MemoryList) CleanAll() error
- func (this *MemoryList) CleanMatchKey(key string) error
- func (this *MemoryList) CleanMatchPrefix(prefix string) error
- func (this *MemoryList) CleanPrefix(prefix string) error
- func (this *MemoryList) Close() error
- func (this *MemoryList) Count() (int64, error)
- func (this *MemoryList) Exist(hash string) (bool, int64, error)
- func (this *MemoryList) IncreaseHit(hash string) error
- func (this *MemoryList) Init() error
- func (this *MemoryList) ItemMaps() map[string]map[string]*Item
- func (this *MemoryList) OnAdd(f func(item *Item))
- func (this *MemoryList) OnRemove(f func(item *Item))
- func (this *MemoryList) Prefixes() []string
- func (this *MemoryList) Print(t *testing.T)
- func (this *MemoryList) Purge(count int, callback func(hash string) error) (int, error)
- func (this *MemoryList) PurgeIndex() int
- func (this *MemoryList) PurgeLFU(count int, callback func(hash string) error) error
- func (this *MemoryList) Remove(hash string) error
- func (this *MemoryList) Reset() error
- func (this *MemoryList) Stat(check func(hash string) bool) (*Stat, error)
- type MemoryReader
- func (this *MemoryReader) BodySize() int64
- func (this *MemoryReader) Close() error
- func (this *MemoryReader) ContainsRange(r rangeutils.Range) (r2 rangeutils.Range, ok bool)
- func (this *MemoryReader) ExpiresAt() int64
- func (this *MemoryReader) HeaderSize() int64
- func (this *MemoryReader) Init() error
- func (this *MemoryReader) LastModified() int64
- func (this *MemoryReader) Read(buf []byte) (n int, err error)
- func (this *MemoryReader) ReadBody(buf []byte, callback ReaderFunc) error
- func (this *MemoryReader) ReadBodyRange(buf []byte, start int64, end int64, callback ReaderFunc) error
- func (this *MemoryReader) ReadHeader(buf []byte, callback ReaderFunc) error
- func (this *MemoryReader) Status() int
- func (this *MemoryReader) TypeName() string
- type MemoryStorage
- func (this *MemoryStorage) AddToList(item *Item)
- func (this *MemoryStorage) CanSendfile() bool
- func (this *MemoryStorage) CanUpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy) bool
- func (this *MemoryStorage) CleanAll() error
- func (this *MemoryStorage) Delete(key string) error
- func (this *MemoryStorage) HasFreeSpaceForHotItems() bool
- func (this *MemoryStorage) IgnoreKey(key string, maxSize int64)
- func (this *MemoryStorage) Init() error
- func (this *MemoryStorage) OpenFlushWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64) (Writer, error)
- func (this *MemoryStorage) OpenReader(key string, useStale bool, isPartial bool) (Reader, error)
- func (this *MemoryStorage) OpenWriter(key string, expiredAt int64, status int, headerSize int, bodySize int64, ...) (Writer, error)
- func (this *MemoryStorage) Policy() *serverconfigs.HTTPCachePolicy
- func (this *MemoryStorage) Purge(keys []string, urlType string) error
- func (this *MemoryStorage) Stat() (*Stat, error)
- func (this *MemoryStorage) Stop()
- func (this *MemoryStorage) TotalDiskSize() int64
- func (this *MemoryStorage) TotalMemorySize() int64
- func (this *MemoryStorage) UpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy)
- type MemoryWriter
- func (this *MemoryWriter) BodySize() int64
- func (this *MemoryWriter) Close() error
- func (this *MemoryWriter) Discard() error
- func (this *MemoryWriter) ExpiredAt() int64
- func (this *MemoryWriter) HeaderSize() int64
- func (this *MemoryWriter) ItemType() ItemType
- func (this *MemoryWriter) Key() string
- func (this *MemoryWriter) Write(data []byte) (n int, err error)
- func (this *MemoryWriter) WriteAt(offset int64, b []byte) error
- func (this *MemoryWriter) WriteHeader(data []byte) (n int, err error)
- type OpenFile
- type OpenFileCache
- func (this *OpenFileCache) Close(filename string)
- func (this *OpenFileCache) CloseAll()
- func (this *OpenFileCache) Debug()
- func (this *OpenFileCache) Get(filename string) *OpenFile
- func (this *OpenFileCache) Put(filename string, file *OpenFile)
- func (this *OpenFileCache) SetCapacity(capacityBytes int64)
- type OpenFilePool
- func (this *OpenFilePool) Close()
- func (this *OpenFilePool) Filename() string
- func (this *OpenFilePool) Get() (resultFile *OpenFile, consumed bool, consumedSize int64)
- func (this *OpenFilePool) Len() int
- func (this *OpenFilePool) Put(file *OpenFile) bool
- func (this *OpenFilePool) SetClosing()
- func (this *OpenFilePool) TotalSize() int64
- type PartialFileReader
- func (this *PartialFileReader) ContainsRange(r rangeutils.Range) (r2 rangeutils.Range, ok bool)
- func (this *PartialFileReader) Init() error
- func (this *PartialFileReader) InitAutoDiscard(autoDiscard bool) error
- func (this *PartialFileReader) IsCompleted() bool
- func (this *PartialFileReader) MaxLength() int64
- func (this *PartialFileReader) Ranges() *PartialRanges
- type PartialFileWriter
- func (this *PartialFileWriter) AppendHeader(data []byte) error
- func (this *PartialFileWriter) BodySize() int64
- func (this *PartialFileWriter) Close() error
- func (this *PartialFileWriter) Discard() error
- func (this *PartialFileWriter) ExpiredAt() int64
- func (this *PartialFileWriter) HeaderSize() int64
- func (this *PartialFileWriter) IsNew() bool
- func (this *PartialFileWriter) ItemType() ItemType
- func (this *PartialFileWriter) Key() string
- func (this *PartialFileWriter) Ranges() *PartialRanges
- func (this *PartialFileWriter) SetBodyLength(bodyLength int64)
- func (this *PartialFileWriter) SetContentMD5(contentMD5 string)
- func (this *PartialFileWriter) Write(data []byte) (n int, err error)
- func (this *PartialFileWriter) WriteAt(offset int64, data []byte) error
- func (this *PartialFileWriter) WriteBodyLength(bodyLength int64) error
- func (this *PartialFileWriter) WriteHeader(data []byte) (n int, err error)
- func (this *PartialFileWriter) WriteHeaderLength(headerLength int) error
- type PartialRanges
- func (this *PartialRanges) Add(begin int64, end int64)
- func (this *PartialRanges) Bytes() []byte
- func (this *PartialRanges) Contains(begin int64, end int64) bool
- func (this *PartialRanges) FindRangeAtPosition(position int64) (r rangeutils.Range, ok bool)
- func (this *PartialRanges) IsCompleted() bool
- func (this *PartialRanges) Max() int64
- func (this *PartialRanges) Nearest(begin int64, end int64) (r [2]int64, ok bool)
- func (this *PartialRanges) Reset()
- func (this *PartialRanges) String() string
- func (this *PartialRanges) WriteToFile(path string) error
- type PartialRangesQueue
- func (this *PartialRangesQueue) Delete(filename string)
- func (this *PartialRangesQueue) Dump()
- func (this *PartialRangesQueue) Get(filename string) ([]byte, error)
- func (this *PartialRangesQueue) Len() int
- func (this *PartialRangesQueue) Put(filename string, data []byte)
- func (this *PartialRangesQueue) Start()
- type Reader
- type ReaderFunc
- type SQLiteFileList
- func (this *SQLiteFileList) Add(hash string, item *Item) error
- func (this *SQLiteFileList) CleanAll() error
- func (this *SQLiteFileList) CleanMatchKey(key string) error
- func (this *SQLiteFileList) CleanMatchPrefix(prefix string) error
- func (this *SQLiteFileList) CleanPrefix(prefix string) error
- func (this *SQLiteFileList) Close() error
- func (this *SQLiteFileList) Count() (int64, error)
- func (this *SQLiteFileList) Exist(hash string) (bool, int64, error)
- func (this *SQLiteFileList) ExistQuick(hash string) (isReady bool, found bool)
- func (this *SQLiteFileList) GetDB(hash string) *SQLiteFileListDB
- func (this *SQLiteFileList) GetDBIndex(hash string) uint64
- func (this *SQLiteFileList) HashMapIsLoaded() bool
- func (this *SQLiteFileList) IncreaseHit(hash string) error
- func (this *SQLiteFileList) Init() error
- func (this *SQLiteFileList) OnAdd(f func(item *Item))
- func (this *SQLiteFileList) OnRemove(f func(item *Item))
- func (this *SQLiteFileList) Purge(count int, callback func(hash string) error) (int, error)
- func (this *SQLiteFileList) PurgeLFU(count int, callback func(hash string) error) error
- func (this *SQLiteFileList) Remove(hash string) error
- func (this *SQLiteFileList) Reset() error
- func (this *SQLiteFileList) SetOldDir(oldDir string)
- func (this *SQLiteFileList) Stat(check func(hash string) bool) (*Stat, error)
- func (this *SQLiteFileList) UpgradeV3(oldDir string, brokenOnError bool) error
- type SQLiteFileListDB
- func (this *SQLiteFileListDB) AddSync(hash string, item *Item) error
- func (this *SQLiteFileListDB) CleanAll() error
- func (this *SQLiteFileListDB) CleanMatchKey(key string) error
- func (this *SQLiteFileListDB) CleanMatchPrefix(prefix string) error
- func (this *SQLiteFileListDB) CleanPrefix(prefix string) error
- func (this *SQLiteFileListDB) Close() error
- func (this *SQLiteFileListDB) DeleteSync(hash string) error
- func (this *SQLiteFileListDB) HashMapIsLoaded() bool
- func (this *SQLiteFileListDB) IncreaseHitAsync(hash string) error
- func (this *SQLiteFileListDB) Init() error
- func (this *SQLiteFileListDB) IsReady() bool
- func (this *SQLiteFileListDB) ListExpiredItems(count int) (hashList []string, err error)
- func (this *SQLiteFileListDB) ListHashes(lastId int64) (hashList []string, maxId int64, err error)
- func (this *SQLiteFileListDB) ListLFUItems(count int) (hashList []string, err error)
- func (this *SQLiteFileListDB) Open(dbPath string) error
- func (this *SQLiteFileListDB) Total() (int64, error)
- func (this *SQLiteFileListDB) WrapError(err error) error
- type SQLiteFileListHashMap
- func (this *SQLiteFileListHashMap) Add(hash string)
- func (this *SQLiteFileListHashMap) AddHashes(hashes []string)
- func (this *SQLiteFileListHashMap) Clean()
- func (this *SQLiteFileListHashMap) Delete(hash string)
- func (this *SQLiteFileListHashMap) Exist(hash string) bool
- func (this *SQLiteFileListHashMap) IsReady() bool
- func (this *SQLiteFileListHashMap) Len() int
- func (this *SQLiteFileListHashMap) Load(db *SQLiteFileListDB) error
- func (this *SQLiteFileListHashMap) SetIsAvailable(isAvailable bool)
- func (this *SQLiteFileListHashMap) SetIsReady(isReady bool)
- type Stat
- type StorageInterface
- type Writer
Constants ¶
const ( SuffixAll = "@GOEDGE_" // 通用后缀 SuffixWebP = "@GOEDGE_WEBP" // WebP后缀 SuffixCompression = "@GOEDGE_" // 压缩后缀 SuffixCompression + Encoding SuffixMethod = "@GOEDGE_" // 请求方法后缀 SuffixMethod + RequestMethod SuffixPartial = "@GOEDGE_partial" // 分区缓存后缀 )
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 )
const ( FileStorageMaxIgnoreKeys = 32768 // 最大可忽略的键值数(尺寸过大的键值) HotItemSize = 1024 // 热点数据数量 HotItemLifeSeconds int64 = 3600 // 热点数据生命周期 FileTmpSuffix = ".tmp" DefaultMinDiskFreeSpace uint64 = 5 << 30 // 当前磁盘最小剩余空间 DefaultStaleCacheSeconds = 1200 // 过时缓存留存时间 HashKeyLength = 32 )
const CountFileDB = 20
const HashMapSharding = 31
Variables ¶
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") ErrWritingQueueFull = errors.New("writing queue full") ErrServerIsBusy = errors.New("server is busy") ErrUnexpectedContentLength = errors.New("unexpected content length") )
常用的几个错误
var FileToMemoryMaxSize int64 = 32 << 20 // 可以从文件写入到内存的最大文件尺寸
Functions ¶
func IsBusyError ¶ added in v1.3.7
func IsCapacityError ¶ added in v1.3.5
func NewCapacityError ¶
func PartialRangesFilePath ¶ added in v1.2.9
PartialRangesFilePath 获取 ranges 文件路径
Types ¶
type BaseReader ¶ added in v1.3.9
type BaseReader struct {
// contains filtered or unexported fields
}
func (*BaseReader) SetNextReader ¶ added in v1.3.9
func (this *BaseReader) SetNextReader(nextReader io.ReadCloser)
SetNextReader 设置下一个内容Reader
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 { BaseReader // contains filtered or unexported fields }
func NewFileReader ¶
func NewFileReader(fp *fsutils.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) 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) 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) CanSendfile ¶
func (this *FileStorage) CanSendfile() bool
CanSendfile 是否支持Sendfile
func (*FileStorage) CanUpdatePolicy ¶
func (this *FileStorage) CanUpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy) bool
CanUpdatePolicy 检查策略是否可以更新
func (*FileStorage) IgnoreKey ¶
func (this *FileStorage) IgnoreKey(key string, maxSize int64)
IgnoreKey 忽略某个Key,即不缓存某个Key
func (*FileStorage) OpenFlushWriter ¶
func (this *FileStorage) OpenFlushWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64) (Writer, error)
OpenFlushWriter 打开从其他媒介直接刷入的写入器
func (*FileStorage) OpenReader ¶
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) Options ¶ added in v1.3.9
func (this *FileStorage) Options() *serverconfigs.HTTPFileCacheStorage
Options 获取当前缓存存储的选项
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) 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 *fsutils.File, key string, expiredAt int64, metaHeaderSize int, metaBodySize int64, maxSize int64, endFunc func()) *FileWriter
func (*FileWriter) BodySize ¶
func (this *FileWriter) BodySize() int64
func (*FileWriter) ExpiredAt ¶
func (this *FileWriter) ExpiredAt() int64
func (*FileWriter) HeaderSize ¶
func (this *FileWriter) HeaderSize() int64
func (*FileWriter) Key ¶
func (this *FileWriter) Key() string
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 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) RequestURI ¶ added in v0.5.8
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 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) Exist ¶ added in v1.3.4
func (this *KVFileList) Exist(hash string) (bool, int64, 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) 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) 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) 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, memCache *ttlcache.Cache[int64]) *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, int64, 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 (*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) (ok bool, size int64, err 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 MMAPFileReader ¶ added in v1.3.5
type MMAPFileReader struct {
FileReader
}
func (*MMAPFileReader) CopyBodyTo ¶ added in v1.3.5
func (this *MMAPFileReader) CopyBodyTo(writer io.Writer) (int, error)
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 (*Manager) FindAllCachePaths ¶
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
MaxSystemMemoryBytesPerStorage 计算单个策略能使用的系统最大内存
func (*Manager) NewStorageWithPolicy ¶
func (this *Manager) NewStorageWithPolicy(policy *serverconfigs.HTTPCachePolicy) StorageInterface
NewStorageWithPolicy 根据策略获取存储对象
func (*Manager) ScanGarbageCaches ¶ added in v1.2.9
ScanGarbageCaches 清理目录中“失联”的缓存文件
func (*Manager) StorageMap ¶ added in v1.3.0
func (this *Manager) StorageMap() map[int64]StorageInterface
StorageMap 获取已有的存储对象
func (*Manager) TotalMemorySize ¶
TotalMemorySize 消耗的内存尺寸
func (*Manager) UpdatePolicies ¶
func (this *Manager) UpdatePolicies(newPolicies []*serverconfigs.HTTPCachePolicy)
UpdatePolicies 重新设置策略
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) 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) 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) 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 ¶
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
type MemoryReader ¶
type MemoryReader struct { BaseReader // 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) 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) 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) OpenFlushWriter ¶
func (this *MemoryStorage) OpenFlushWriter(key string, expiresAt int64, status int, headerSize int, bodySize int64) (Writer, error)
OpenFlushWriter 打开从其他媒介直接刷入的写入器
func (*MemoryStorage) OpenReader ¶
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 ¶
func (this *MemoryStorage) Policy() *serverconfigs.HTTPCachePolicy
Policy 获取当前存储的Policy
func (*MemoryStorage) Purge ¶
func (this *MemoryStorage) Purge(keys []string, urlType string) error
Purge 批量删除缓存
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) 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 ¶
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 *fsutils.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) IsCompleted ¶ added in v1.3.5
func (this *PartialFileReader) IsCompleted() bool
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 (*PartialFileWriter) AppendHeader ¶
func (this *PartialFileWriter) AppendHeader(data []byte) error
func (*PartialFileWriter) BodySize ¶
func (this *PartialFileWriter) BodySize() int64
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) Ranges ¶ added in v1.3.9
func (this *PartialFileWriter) Ranges() *PartialRanges
func (*PartialFileWriter) SetBodyLength ¶
func (this *PartialFileWriter) SetBodyLength(bodyLength int64)
SetBodyLength 设置内容总长度
func (*PartialFileWriter) SetContentMD5 ¶ added in v1.3.9
func (this *PartialFileWriter) SetContentMD5(contentMD5 string)
SetContentMD5 设置内容MD5
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"` // 总长度 ContentMD5 string `json:"contentMD5"` // 内容md5 }
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) 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) FindRangeAtPosition ¶ added in v1.3.9
func (this *PartialRanges) FindRangeAtPosition(position int64) (r rangeutils.Range, ok bool)
FindRangeAtPosition 查找在某个位置上的范围
func (*PartialRanges) IsCompleted ¶ added in v1.3.5
func (this *PartialRanges) IsCompleted() bool
IsCompleted 是否已下载完整
func (*PartialRanges) Nearest ¶
func (this *PartialRanges) Nearest(begin int64, end int64) (r [2]int64, ok bool)
Nearest 查找最近的某个范围
func (*PartialRanges) WriteToFile ¶
func (this *PartialRanges) WriteToFile(path string) error
WriteToFile 写入到文件中
type PartialRangesQueue ¶ added in v1.3.5
type PartialRangesQueue struct {
// contains filtered or unexported fields
}
PartialRangesQueue ranges file writing queue
func NewPartialRangesQueue ¶ added in v1.3.5
func NewPartialRangesQueue() *PartialRangesQueue
NewPartialRangesQueue Create new queue
func (*PartialRangesQueue) Delete ¶ added in v1.3.5
func (this *PartialRangesQueue) Delete(filename string)
Delete ranges filename
func (*PartialRangesQueue) Dump ¶ added in v1.3.5
func (this *PartialRangesQueue) Dump()
Dump ranges to filename from memory
func (*PartialRangesQueue) Get ¶ added in v1.3.5
func (this *PartialRangesQueue) Get(filename string) ([]byte, error)
Get ranges data from filename
func (*PartialRangesQueue) Len ¶ added in v1.3.5
func (this *PartialRangesQueue) Len() int
Len count all files
func (*PartialRangesQueue) Put ¶ added in v1.3.5
func (this *PartialRangesQueue) Put(filename string, data []byte)
Put ranges data to filename
func (*PartialRangesQueue) Start ¶ added in v1.3.5
func (this *PartialRangesQueue) Start()
Start the queue
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) // SetNextReader 设置下一个内容Reader SetNextReader(nextReader io.ReadCloser) // Close 关闭 Close() error }
type ReaderFunc ¶
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, int64, 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
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)
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 (this *SQLiteFileListHashMap) Load(db *SQLiteFileListDB) error
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 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 缓存内容写入接口
Source Files ¶
- consts.go
- errors.go
- file_dir.go
- hot_item.go
- item.go
- list_file_db_sqlite.go
- list_file_hash_map_sqlite.go
- list_file_kv.go
- list_file_kv_objects.go
- list_file_kv_store.go
- list_file_sqlite.go
- list_interface.go
- list_memory.go
- manager.go
- open_file.go
- open_file_cache.go
- open_file_pool.go
- partial_ranges.go
- partial_ranges_queue.go
- reader.go
- reader_base.go
- reader_file.go
- reader_file_mmap.go
- reader_memory.go
- reader_partial_file.go
- stat.go
- storage_file.go
- storage_file_ext.go
- storage_interface.go
- storage_memory.go
- utils.go
- utils_partial.go
- writer.go
- writer_file.go
- writer_memory.go
- writer_partial_file.go