mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-11-26 03:45:06 +08:00
* feat(cache): improve cache management * feat(disk-usage): add cache * feat(disk-usage): add refresh * fix(disk-usage): cache with ttl * feat(cache): implement KeyedCache and TypedCache for improved caching mechanism * fix(copy): update object retrieval to use Get instead of GetUnwrap * refactor(cache): simplify DirectoryCache structure and improve object management * fix(cache): correct cache entry initialization and key deletion logic in TypedCache * refactor(driver): remove GetObjInfo interface and simplify Link function logic https://github.com/OpenListTeam/OpenList/pull/888/files#r2430925783 * fix(link): optimize link retrieval and caching logic * refactor(cache): consolidate cache management and improve directory cache handling * fix(cache): add cache control based on storage configuration in List function * . * refactor: replace fmt.Sprintf with strconv for integer conversions * refactor(cache): enhance cache entry management with Expirable interface * fix(cache): improve link reference acquisition logic to handle expiration * refactor: replace OnlyLinkMFile with NoLinkSF in driver configurations and logic * refactor(link): enhance link caching logic with dynamic type keys based on IP and User-Agent * feat(drivers): add LinkCacheType to driver configurations for enhanced caching * refactor(cache): streamline directory object management in cache operations * refactor(cache): remove unnecessary 'dirty' field from CacheEntry structure * refactor(cache): replace 'dirty' field with bitwise flags * refactor(io): 调高SyncClosers.AcquireReference的优先级 * refactor(link): 优化链接获取逻辑,增加重 * refactor(link): 添加RequireReference字段以增强链接管理 * refactor(link): 移除MFile字段,改用RangeReader * refactor: 移除不必要的NoLinkSF字段 * refactor(cache): 修改目录缓存的脏标志定义和更新逻辑 * feat(cache): add expiration gc --------- Co-authored-by: KirCute <951206789@qq.com> Co-authored-by: KirCute <kircute@foxmail.com> Co-authored-by: j2rong4cn <j2rong@qq.com>
123 lines
2.3 KiB
Go
123 lines
2.3 KiB
Go
package model
|
||
|
||
import (
|
||
"context"
|
||
"io"
|
||
"net/http"
|
||
"time"
|
||
|
||
"github.com/OpenListTeam/OpenList/v4/pkg/http_range"
|
||
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
||
)
|
||
|
||
type ListArgs struct {
|
||
ReqPath string
|
||
S3ShowPlaceholder bool
|
||
Refresh bool
|
||
WithStorageDetails bool
|
||
}
|
||
|
||
type LinkArgs struct {
|
||
IP string
|
||
Header http.Header
|
||
Type string
|
||
Redirect bool
|
||
}
|
||
|
||
type Link struct {
|
||
URL string `json:"url"` // most common way
|
||
Header http.Header `json:"header"` // needed header (for url)
|
||
RangeReader RangeReaderIF `json:"-"` // recommended way if can't use URL
|
||
|
||
Expiration *time.Duration // local cache expire Duration
|
||
|
||
//for accelerating request, use multi-thread downloading
|
||
Concurrency int `json:"concurrency"`
|
||
PartSize int `json:"part_size"`
|
||
ContentLength int64 `json:"-"` // 转码视频、缩略图
|
||
|
||
utils.SyncClosers `json:"-"`
|
||
// 如果SyncClosers中的资源被关闭后Link将不可用,则此值应为 true
|
||
RequireReference bool `json:"-"`
|
||
}
|
||
|
||
type OtherArgs struct {
|
||
Obj Obj
|
||
Method string
|
||
Data interface{}
|
||
}
|
||
|
||
type FsOtherArgs struct {
|
||
Path string `json:"path" form:"path"`
|
||
Method string `json:"method" form:"method"`
|
||
Data interface{} `json:"data" form:"data"`
|
||
}
|
||
|
||
type ArchiveArgs struct {
|
||
Password string
|
||
LinkArgs
|
||
}
|
||
|
||
type ArchiveInnerArgs struct {
|
||
ArchiveArgs
|
||
InnerPath string
|
||
}
|
||
|
||
type ArchiveMetaArgs struct {
|
||
ArchiveArgs
|
||
Refresh bool
|
||
}
|
||
|
||
type ArchiveListArgs struct {
|
||
ArchiveInnerArgs
|
||
Refresh bool
|
||
}
|
||
|
||
type ArchiveDecompressArgs struct {
|
||
ArchiveInnerArgs
|
||
CacheFull bool
|
||
PutIntoNewDir bool
|
||
}
|
||
|
||
type SharingListArgs struct {
|
||
Refresh bool
|
||
Pwd string
|
||
}
|
||
|
||
type SharingArchiveMetaArgs struct {
|
||
ArchiveMetaArgs
|
||
Pwd string
|
||
}
|
||
|
||
type SharingArchiveListArgs struct {
|
||
ArchiveListArgs
|
||
Pwd string
|
||
}
|
||
|
||
type SharingLinkArgs struct {
|
||
Pwd string
|
||
LinkArgs
|
||
}
|
||
|
||
type RangeReaderIF interface {
|
||
RangeRead(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error)
|
||
}
|
||
|
||
type RangeReadCloserIF interface {
|
||
RangeReaderIF
|
||
utils.ClosersIF
|
||
}
|
||
|
||
var _ RangeReadCloserIF = (*RangeReadCloser)(nil)
|
||
|
||
type RangeReadCloser struct {
|
||
RangeReader RangeReaderIF
|
||
utils.Closers
|
||
}
|
||
|
||
func (r *RangeReadCloser) RangeRead(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error) {
|
||
rc, err := r.RangeReader.RangeRead(ctx, httpRange)
|
||
r.Add(rc)
|
||
return rc, err
|
||
}
|