cache

package
v0.12.30 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: LGPL-3.0, LGPL-3.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// Cache settings
	MaxFileCacheSize = 5 << 20 // 5MB max file size for caching

	// Compression threshold - only compress files larger than this
	CompressionThreshold = 5 << 10 // 5KB

	// Default cache expiration times
	DefaultCacheExpiry = 24 * time.Hour      // Default expiry time for cached files
	ImageCacheExpiry   = 7 * 24 * time.Hour  // 7 days for images
	TextCacheExpiry    = 24 * time.Hour      // 1 day for text files
	VideoCacheExpiry   = 14 * 24 * time.Hour // 14 days for videos

	// Worker pool settings
	WorkerPoolSize = 100

	// Olric cache namespace
	AssetsCacheNamespace = "assets-cache"
)

Variables

This section is empty.

Functions

func CalculateExpiry

func CalculateExpiry(mimeType, path string) time.Time

CalculateExpiry determines expiry time based on file type

func CompressData

func CompressData(data []byte) ([]byte, error)

CompressData compresses data using gzip

func GenerateETag

func GenerateETag(content []byte, modTime time.Time) string

func GetMimeType

func GetMimeType(filename string) string

GetMimeType determines the MIME type based on file extension with additional types

func ShouldBeDownloaded

func ShouldBeDownloaded(mimeType string, filename string) bool

ShouldBeDownloaded determines if the file should be served as a download

func ShouldCompress

func ShouldCompress(contentType string) bool

ShouldCompress determines if a file should be compressed based on its content type

Types

type CachedFile

type CachedFile struct {
	Data            []byte
	ETag            string
	Modtime         time.Time
	MimeType        string
	Path            string
	Size            int
	GzipData        []byte    // Pre-compressed version for text files
	IsDownload      bool      // Whether file should be downloaded or displayed inline
	ExpiresAt       time.Time // When this cache entry expires
	FileStat        FileStat  // File stat information for validation
	AuthzVersion    byte
	TablePermission permission.PermissionInstance
	RowPermission   permission.PermissionInstance
	AdminGroupId    daptinid.DaptinReferenceId
}

CachedFile represents a cached file with its metadata

func (*CachedFile) MarshalBinary

func (cf *CachedFile) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler interface for Olric compatibility Custom binary format without using gob or other encoders

func (*CachedFile) UnmarshalBinary

func (cf *CachedFile) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler interface for Olric compatibility Custom binary format without using gob or other encoders

type FileCache

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

FileCache implements a file caching system using Olric distributed cache

func NewFileCache

func NewFileCache(olricClient *olric.EmbeddedClient, namespace string) (*FileCache, error)

NewFileCache creates a new file cache using Olric

func (*FileCache) Close

func (fc *FileCache) Close()

Close properly shuts down the cache

func (*FileCache) Get

func (fc *FileCache) Get(key string) (*CachedFile, bool)

Get retrieves a file from cache if it exists and is valid

func (*FileCache) Remove

func (fc *FileCache) Remove(key string)

Remove removes an entry from cache

func (*FileCache) RemoveAsync

func (fc *FileCache) RemoveAsync(key string)

RemoveAsync removes an entry from cache asynchronously using worker pool

func (*FileCache) Set

func (fc *FileCache) Set(key string, file *CachedFile)

Set adds a file to the cache with appropriate expiry

type FileStat

type FileStat struct {
	ModTime time.Time
	Size    int64
	Exists  bool
}

FileStat stores file information for validation

func GetFileStat

func GetFileStat(path string) (FileStat, error)

GetFileStat gets file info for validation

Jump to

Keyboard shortcuts

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