cache

package
v0.0.0-...-e41826d Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheMiss     = errors.New("requested resource not cached")
	ErrAlreadyCached = errors.New("resource already cached")
	ErrNotComplete   = errors.New("download is not complete")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Put(*url.URL, matrix.File) (<-chan int64, <-chan error)

	// Get gets a file from the cache if it was put there.
	Get(url *url.URL) (matrix.File, error)

	PutThumbnail(url *url.URL, method matrix.ThumbnailMethod, width, height int, thumb matrix.Thumbnail) (<-chan int64, <-chan error)

	// Get gets a thumbnail from the cache if it was put there.
	GetThumbnail(url *url.URL, method matrix.ThumbnailMethod, width, height int) (matrix.Thumbnail, error)
}

Cache specifies a common interface for caching content. Since mxc:// URIs are staic, a single Cache can be shared between multiple clients. A Cache implementation must be fully threadsafe. Resulting errors can be divided into three categories: error occured in download code (i.e connection lost), error occured in storing code (i.e insufficient permissions) or error occured due to incorrect usage of the Cache (i.e ErrCacheMiss, ErrAlreadyCached, ErrNotComplete). A error type exists for each category (DownloadError, StorageError, UsageError respectively). Implementations must use them.

type DownloadError

type DownloadError struct {
	Err error
}

DownloadError is returned by Cache when an error occures in the downloading code (i.e connection lost). It wraps the original error.

func (DownloadError) Error

func (e DownloadError) Error() string

func (DownloadError) Unwrap

func (e DownloadError) Unwrap() error

type FSCache

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

FSCache stores content on the filesystem Files: $path/files/${url.Host}/${url.Path}/${file.Type}.${file.Name} Thumbnails: ${path}/thumbnails/${url.Host}/${url.Path}/${method}/${width}x${height}/${base64encode thumb.Type}

func NewFSCache

func NewFSCache(path string) (FSCache, error)

func (FSCache) Get

func (c FSCache) Get(uri *url.URL) (matrix.File, error)

func (FSCache) GetThumbnail

func (c FSCache) GetThumbnail(url *url.URL, method matrix.ThumbnailMethod, width, height int) (matrix.Thumbnail, error)

func (FSCache) Put

func (c FSCache) Put(uri *url.URL, file matrix.File) (<-chan int64, <-chan error)

func (FSCache) PutThumbnail

func (c FSCache) PutThumbnail(url *url.URL, method matrix.ThumbnailMethod, width, height int, thumb matrix.Thumbnail) (<-chan int64, <-chan error)

type MemoryCache

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

func (*MemoryCache) Get

func (c *MemoryCache) Get(uri *url.URL) (matrix.File, error)

func (*MemoryCache) GetThumbnail

func (c *MemoryCache) GetThumbnail(uri *url.URL, method matrix.ThumbnailMethod, width, height int) (matrix.Thumbnail, error)

func (*MemoryCache) Put

func (c *MemoryCache) Put(uri *url.URL, file matrix.File) (<-chan int64, <-chan error)

func (*MemoryCache) PutThumbnail

func (c *MemoryCache) PutThumbnail(uri *url.URL, method matrix.ThumbnailMethod, width, height int, thumb matrix.Thumbnail) (<-chan int64, <-chan error)

type StorageError

type StorageError struct {
	Err error
}

StorageError is returned by Cache when an error occures in the storing code (i.e insufficient permissions). It wraps the original error.

func (StorageError) Error

func (e StorageError) Error() string

func (StorageError) Unwrap

func (e StorageError) Unwrap() error

type UsageError

type UsageError struct {
	Err error
}

UsageError is returned by Cache when an error due to incorrect usage of a Cache (i.e ErrCacheMiss, ErrNotCompleted). It wraps the original error.

func (UsageError) Error

func (e UsageError) Error() string

func (UsageError) Unwrap

func (e UsageError) Unwrap() error

Jump to

Keyboard shortcuts

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