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 LastAccessEviction
- type Layer
- func (l *Layer) BackgroundEviction(ctx context.Context, dur time.Duration)
- func (l *Layer) Delete(ctx context.Context, name string) error
- func (l *Layer) Evict(ctx context.Context) (count int)
- func (l *Layer) Exists(ctx context.Context, name string) bool
- func (l *Layer) Get(ctx context.Context, name string) ([]byte, error)
- func (l *Layer) Put(ctx context.Context, name string, content []byte) error
- func (l *Layer) Stats() *LayerStats
- type LayerStats
- type MaxCacheSizeEviction
- type MaxItemsEviction
- type Memory
- type NestedFileSystem
- func (nfs *NestedFileSystem) Delete(_ context.Context, name string) error
- func (nfs *NestedFileSystem) Exists(_ context.Context, name string) bool
- func (nfs *NestedFileSystem) Get(_ context.Context, name string) ([]byte, error)
- func (nfs *NestedFileSystem) Put(_ context.Context, name string, content []byte) error
- 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 ErrNotInMemory = errors.New("does not exist in memory cache")
ErrNotInMemory is returned if an item does not exists in Memory
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 from the Storer. Items are removed from the cache when certain criteria from each Layer are hit.
func (*Cache) Clear ¶
Clear a single item from the cache. There is no feedback on how successful the operation was and which layer produced an error.
type Cacher ¶
type Cacher interface { Put(ctx context.Context, name string, content []byte) error Exists(ctx context.Context, name string) bool Delete(ctx context.Context, name string) error Get(ctx context.Context, name string) ([]byte, error) }
Cacher is the interface Cache expects to cache transformed images to.
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)
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) Evict ¶ added in v0.1.1
Evict instructs all Evictionstrategies to remove items that need to be evicted. Returns the number of items that were evicted.
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 Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory can be used as a Storer or Cacher.
func (*Memory) Delete ¶
Delete an item from Memory. It does not return an error ever, if the item does not exist nothing else happens.
func (*Memory) Get ¶
Get an item from Memory. If the item does not exists it return ErrNotInMemory as the error.
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(_ context.Context, name string) error
func (*NestedFileSystem) Exists ¶
func (nfs *NestedFileSystem) Exists(_ context.Context, name string) bool