Documentation
¶
Index ¶
- Constants
- Variables
- func GetSupportedTypes() []bimg.ImageType
- func SupportsType(t bimg.ImageType) bool
- type Cache
- type Cacher
- type EvictionStrategy
- type FileSystem
- type Handler
- type Item
- type LastAccessEviction
- type Layer
- func (l *Layer) BackgroundEviction(ctx context.Context, dur time.Duration)
- func (l *Layer) Delete(name string) error
- func (l *Layer) Evict() (count int)
- func (l *Layer) Exists(name string) bool
- func (l *Layer) Get(name string) ([]byte, error)
- func (l *Layer) Put(name string, content []byte) error
- func (l *Layer) Stats() *LayerStats
- type LayerStats
- type MaxCacheSizeEviction
- type MaxItemsEviction
- type Memory
- type NestedFileSystem
- type Storer
Constants ¶
const ( KB = 1024 MB = KB * 1024 GB = MB * 1024 )
Prefixes that help to calculate cache sizes.
// 1GB const MaxSize = 1 * imageCache.GB
Variables ¶
var NotInMemory = errors.New("does not exist in memory cache")
Functions ¶
func GetSupportedTypes ¶
GetSupportedTypes get a slice of all supported image formats. The results are reported by bimg.ImageType
func SupportsType ¶
SupportsType check if image format bimg.ImageType is supported by the current installation of libvips
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache caches items
func New ¶
Creates a new Cache. Items are taken frrom the [Store]. Items are removed from the cache when certain criteria from each Layer are hit.
type EvictionStrategy ¶
type EvictionStrategy interface {
// contains filtered or unexported methods
}
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
func NewFileSystem ¶
func NewFileSystem(path string) (*FileSystem, error)
func (*FileSystem) Delete ¶
func (fs *FileSystem) Delete(name string) error
func (*FileSystem) Exists ¶
func (fs *FileSystem) Exists(name string) bool
type Handler ¶
type Handler func(string, http.ResponseWriter)
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item within the caching layer TODO: this does not need to be exported
type LastAccessEviction ¶
type LastAccessEviction struct {
// contains filtered or unexported fields
}
LastAccessEviction evicts items after a certain time not being accessed
func NewLastAccessEviction ¶
func NewLastAccessEviction(duration time.Duration) *LastAccessEviction
NewLastAccessEviction creates a new EvictionStrategy based on the time of the last access
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
Layer represents a caching layer
func NewLayer ¶
func NewLayer(cache Cacher, evictions ...EvictionStrategy) *Layer
NewLayer creates a new caching layer with various eviction strategies. If no evicition strategy is passed the items will never be deleted.
func (*Layer) BackgroundEviction ¶
BackgroundEviction enabled eviction of stale items in the background. Items are checked for eviction according to dur. This function blocks and stop it provide a Context that can be canceled.
func (*Layer) Delete ¶
Delete an items from the underlying cache. The exact error depends on the underlying cache implementation.
func (*Layer) Exists ¶
Exists checks if an items exists in the underlying cache. Does not count as an access.
func (*Layer) Get ¶
Get an item from the layer. Returns the content or an error if something went wrong. The behavior of the error depends on the underlying cache. This also counts as an access to the item.
func (*Layer) Put ¶
Put an item into the layer. Required a key and the content itself. Returns an error if something went wrong. The exact error depends on the underlying cache. If the item already exists the item is overwritten. This also counts as an access to the item.
func (*Layer) Stats ¶
func (l *Layer) Stats() *LayerStats
Stats returns the current state of the layer.
type LayerStats ¶
LayerStats contains information about the cache items in the layer
- Count of items
- Size of items in bytes
type MaxCacheSizeEviction ¶
type MaxCacheSizeEviction struct {
// contains filtered or unexported fields
}
MaxCacheSizeEviction evict items when a certain size is reached. Items are evicted in the order of their last access.
func NewMaxCacheSizeEviction ¶
func NewMaxCacheSizeEviction(size int64) *MaxCacheSizeEviction
NewMaxCacheSizeEviction creates a new EvictionStrategy which evicts items by their last access when a certain size is reached.
type MaxItemsEviction ¶
type MaxItemsEviction struct {
// contains filtered or unexported fields
}
MaxItemsEviction evict items when a certain number of items is reached. Items are evicted in the order of their last access.
func NewMaxItemsEviction ¶
func NewMaxItemsEviction(number int) *MaxItemsEviction
NewMaxItemsEviction create a new EvictionStrategy which evicts items when a certain number of items are in the layer. Items are evicted in the order by their last access.
type NestedFileSystem ¶
type NestedFileSystem struct {
// contains filtered or unexported fields
}
func NewNestedFilesystem ¶
func NewNestedFilesystem(path string, numSubdirectories uint) (*NestedFileSystem, error)
func (*NestedFileSystem) Delete ¶
func (nfs *NestedFileSystem) Delete(name string) error
func (*NestedFileSystem) Exists ¶
func (nfs *NestedFileSystem) Exists(name string) bool