cache

package
Version: v0.0.0-...-4bdd3a7 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cache provides a base for an Image cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Async

type Async struct {
	Cache
}

Async is an asynchronous Cache implementation.

The Images are set from a new goroutine.

func (*Async) Set

func (a *Async) Set(key string, image *imageserver.Image, params imageserver.Params) error

Set implements Cache.

type Cache

type Cache interface {
	// Get returns the Image associated to the key, or nil if not found.
	Get(key string, params imageserver.Params) (*imageserver.Image, error)

	// Set adds the Image and associate it to the key.
	Set(key string, image *imageserver.Image, params imageserver.Params) error
}

Cache represents an Image cache.

The Params can be used for custom behavior (no-cache, expiration, ...).

type Func

type Func struct {
	GetFunc func(key string, params imageserver.Params) (*imageserver.Image, error)
	SetFunc func(key string, image *imageserver.Image, params imageserver.Params) error
}

Func is a Cache implementation that forwards calls to user defined functions

func (*Func) Get

func (c *Func) Get(key string, params imageserver.Params) (*imageserver.Image, error)

Get implements Cache.

func (*Func) Set

func (c *Func) Set(key string, image *imageserver.Image, params imageserver.Params) error

Set implements Cache.

type IgnoreError

type IgnoreError struct {
	Cache
}

IgnoreError is a Cache implementation that ignores error from the underlying Cache.

func (*IgnoreError) Get

func (c *IgnoreError) Get(key string, params imageserver.Params) (*imageserver.Image, error)

Get implements Cache.

func (*IgnoreError) Set

func (c *IgnoreError) Set(key string, image *imageserver.Image, params imageserver.Params) error

Set implements Cache.

type KeyGenerator

type KeyGenerator interface {
	GetKey(imageserver.Params) string
}

KeyGenerator represents a Cache key generator.

func NewParamsHashKeyGenerator

func NewParamsHashKeyGenerator(newHashFunc func() hash.Hash) KeyGenerator

NewParamsHashKeyGenerator returns a new KeyGenerator that hashes the Params.

type KeyGeneratorFunc

type KeyGeneratorFunc func(imageserver.Params) string

KeyGeneratorFunc is a KeyGenerator func.

func (KeyGeneratorFunc) GetKey

func (f KeyGeneratorFunc) GetKey(params imageserver.Params) string

GetKey implements KeyGenerator.

type PrefixKeyGenerator

type PrefixKeyGenerator struct {
	KeyGenerator
	Prefix string
}

PrefixKeyGenerator is a KeyGenerator implementation that adds a prefix to the key.

func (*PrefixKeyGenerator) GetKey

func (g *PrefixKeyGenerator) GetKey(params imageserver.Params) string

GetKey implements KeyGenerator.

type Server

type Server struct {
	imageserver.Server
	Cache        Cache
	KeyGenerator KeyGenerator
}

Server is a imageserver.Server implementation that supports a Cache.

Steps:

- Generate the cache key.
- Get the Image from the Cache, and return it if found.
- Get the Image from the Server.
- Set the Image to the Cache.
- Return the Image.

func (*Server) Get

func (s *Server) Get(params imageserver.Params) (*imageserver.Image, error)

Get implements imageserver.Server.

Source Files

Directories

Path Synopsis
Package _test provides utilities for imageserver/cache.Cache testing.
Package _test provides utilities for imageserver/cache.Cache testing.
Package file provides a disk based cache.
Package file provides a disk based cache.
Package memcache provides a Memcache imageserver/cache.Cache implementation.
Package memcache provides a Memcache imageserver/cache.Cache implementation.
Package memory provides an in-memory imageserver/cache.Cache implementation.
Package memory provides an in-memory imageserver/cache.Cache implementation.
Package redis provides a Redis imageserver/cache.Cache implementation.
Package redis provides a Redis imageserver/cache.Cache implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL