Documentation
¶
Overview ¶
Package disk provides a disk-backed cache implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockCache ¶
type BlockCache struct {
// contains filtered or unexported fields
}
BlockCache provides a disk-backed block cache for ByteSources. Blocks are stored as individual files in a directory hierarchy with optional sharding by key prefix. The cache is safe for concurrent use.
func NewBlockCache ¶
func NewBlockCache(dir string, opts ...BlockCacheOption) (*BlockCache, error)
NewBlockCache creates a disk-backed block cache rooted at dir.
func (*BlockCache) MaxBytes ¶
func (c *BlockCache) MaxBytes() int64
MaxBytes returns the configured cache size limit (0 = unlimited).
func (*BlockCache) Prune ¶
func (c *BlockCache) Prune(targetBytes int64) (int64, error)
Prune removes cached entries until the cache is at or below targetBytes.
func (*BlockCache) SizeBytes ¶
func (c *BlockCache) SizeBytes() int64
SizeBytes returns the current cache size in bytes.
func (*BlockCache) Wrap ¶
func (c *BlockCache) Wrap(src blobcache.ByteSource, opts ...blobcache.WrapOption) (blobcache.ByteSource, error)
Wrap returns a ByteSource that caches reads in fixed-size blocks.
type BlockCacheOption ¶
type BlockCacheOption func(*BlockCache)
BlockCacheOption configures a disk-backed block cache.
func WithBlockDirPerm ¶
func WithBlockDirPerm(mode os.FileMode) BlockCacheOption
WithBlockDirPerm sets the directory permissions used for cache directories.
func WithBlockLogger ¶
func WithBlockLogger(logger *slog.Logger) BlockCacheOption
WithBlockLogger sets the logger for block cache operations. If not set, logging is disabled.
func WithBlockMaxBytes ¶
func WithBlockMaxBytes(n int64) BlockCacheOption
WithBlockMaxBytes sets the maximum size in bytes for the block cache. Values <= 0 disable the limit.
func WithBlockShardPrefixLen ¶
func WithBlockShardPrefixLen(n int) BlockCacheOption
WithBlockShardPrefixLen sets the number of hex characters used for sharding. Use 0 to disable sharding. Defaults to 2.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache implements cache.Cache using the local filesystem. Files are stored in a directory hierarchy with optional sharding by hash prefix. The cache is safe for concurrent use.
func (*Cache) Get ¶
Get returns an fs.File for reading cached content. Returns nil, false if the content is not cached.
type Option ¶
type Option func(*Cache)
Option configures a disk cache.
func WithDirPerm ¶
WithDirPerm sets the directory permissions used for cache directories.
func WithLogger ¶
WithLogger sets the logger for cache operations. If not set, logging is disabled.
func WithMaxBytes ¶
WithMaxBytes sets the maximum cache size in bytes. Values < 0 are invalid. Use 0 to disable the limit.
func WithShardPrefixLen ¶
WithShardPrefixLen sets the number of hex characters used for sharding. Use 0 to disable sharding. Defaults to 2.