Documentation
¶
Index ¶
- Constants
- func CalculateExpiry(mimeType, path string) time.Time
- func CompressData(data []byte) ([]byte, error)
- func GenerateETag(content []byte, modTime time.Time) string
- func GetMimeType(filename string) string
- func ShouldBeDownloaded(mimeType string, filename string) bool
- func ShouldCompress(contentType string) bool
- type CachedFile
- type FileCache
- type FileStat
Constants ¶
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 ¶
CalculateExpiry determines expiry time based on file type
func CompressData ¶
CompressData compresses data using gzip
func GetMimeType ¶
GetMimeType determines the MIME type based on file extension with additional types
func ShouldBeDownloaded ¶
ShouldBeDownloaded determines if the file should be served as a download
func ShouldCompress ¶
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) Get ¶
func (fc *FileCache) Get(key string) (*CachedFile, bool)
Get retrieves a file from cache if it exists and is valid
func (*FileCache) RemoveAsync ¶
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