imagecache

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 16 Imported by: 0

README

imagecache

Documentation

Index

Constants

View Source
const (
	KB = 1024
	MB = KB * 1024
	GB = MB * 1024
)

Prefixes that help to calculate cache sizes.

// 1GB
const MaxSize = 1 * imageCache.GB

Variables

View Source
var NotInMemory = errors.New("does not exist in memory cache")

Functions

func GetSupportedTypes

func GetSupportedTypes() []bimg.ImageType

GetSupportedTypes get a slice of all supported image formats. The results are reported by bimg.ImageType

func SupportsType

func SupportsType(t bimg.ImageType) bool

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

func New(store Storer, layers ...*Layer) *Cache

Creates a new Cache. Items are taken frrom the [Store]. Items are removed from the cache when certain criteria from each Layer are hit.

func (*Cache) Clear

func (c *Cache) Clear(name string)

Clear a single item from the cache. There is no feedback on how successful the operation was and which layer produced an error.

func (*Cache) EvictAll added in v0.1.1

func (c *Cache) EvictAll() (count int)

func (*Cache) Handle

func (c *Cache) Handle(imageType bimg.ImageType, config bimg.Options) (Handler, error)

type Cacher

type Cacher interface {
	Put(name string, content []byte) error
	Exists(name string) bool
	Delete(name string) error
	Get(name string) ([]byte, error)
}

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

func (*FileSystem) Get

func (fs *FileSystem) Get(name string) ([]byte, error)

func (*FileSystem) Put

func (fs *FileSystem) Put(name string, data []byte) error

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

func (l *Layer) BackgroundEviction(ctx context.Context, dur time.Duration)

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

func (l *Layer) Delete(name string) error

Delete an items from the underlying cache. The exact error depends on the underlying cache implementation.

func (*Layer) Evict added in v0.1.1

func (l *Layer) Evict() (count int)

func (*Layer) Exists

func (l *Layer) Exists(name string) bool

Exists checks if an items exists in the underlying cache. Does not count as an access.

func (*Layer) Get

func (l *Layer) Get(name string) ([]byte, error)

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

func (l *Layer) Put(name string, content []byte) error

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

type LayerStats struct {
	Count int32
	Size  int64
}

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
}

func NewMemory

func NewMemory() *Memory

func (*Memory) Delete

func (m *Memory) Delete(name string) error

func (*Memory) Exists

func (m *Memory) Exists(name string) bool

func (*Memory) Get

func (m *Memory) Get(name string) ([]byte, error)

func (*Memory) Put

func (m *Memory) Put(name string, content []byte) 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(name string) error

func (*NestedFileSystem) Exists

func (nfs *NestedFileSystem) Exists(name string) bool

func (*NestedFileSystem) Get

func (nfs *NestedFileSystem) Get(name string) ([]byte, error)

func (*NestedFileSystem) Put

func (nfs *NestedFileSystem) Put(name string, content []byte) error

type Storer

type Storer interface {
	Exists(name string) bool
	Get(name string) ([]byte, error)
}

Directories

Path Synopsis
this the double linked list from https://pkg.go.dev/container/list the only change is, that it uses generics for the value
this the double linked list from https://pkg.go.dev/container/list the only change is, that it uses generics for the value

Jump to

Keyboard shortcuts

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