gocache

package
v1.9.14 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 10 Imported by: 0

README

Gocache.

Компонент, который позволяет подключаться к go-cache.
GO-CACHE кэширует данные в памяти приложения.
Реализует интерфейс cache.CacheInterface[[]byte], который доступен в контейнере объектов если этот компонент используется напрямую.

В пакете с компонентом так же имеется метод New, который возвращает ссылку на новый объект github.com/patrickmn/go-cache/Cache для использования его вне контейнера.

Объект конфигурации.
type Config struct {
	Expiration      time.Duration
	CleanupInterval time.Duration
}

Описание полей:

Поле Описание Значение по умолчанию
Expiration Время хранения записи по умолчанию, этот параметр может быть передан одним из 3-х методов:
- флаг командной строки --cache.app.expiration
- переменная окружения CACHE_APP_EXPIRATION
- значение в конфиг файле cache.app.expiration
5 минут
CleanupInterval Интервал очистки кэша от "протухших" записей, этот параметр может быть передан одним из 3-х методов:
- флаг командной строки --cache.app.cleanup
- переменная окружения CACHE_APP_CLEANUP
- значение в конфиг файле cache.app.cleanup
10 минут

Компонент добавляет метрики. Подробнее о метриках https://github.com/eko/gocache.

Documentation

Index

Constants

View Source
const (
	ExpirationFieldName      = "cache.app.expiration"
	CleanupIntervalFieldName = "cache.app.cleanup"

	ExpirationDefault      = 5 * time.Minute
	CleanupIntervalDefault = 10 * time.Minute
)

Variables

View Source
var Component = &app.Component{
	Dependencies: app.Components{
		logger.Component,
		configurator.Component,
		reConfiguration.Component,
	},
	Constructor: app.Constructor(func(container container.Container) error {
		return container.Provides(
			NewConfig,
			NewReConfigurationWithConfigurator,
			func(reConfiguration *ReConfiguration) Cache { return reConfiguration },
		)
	}),
	BindFlags: app.BindFlags(func(flagSet *pflag.FlagSet, container container.Container) error {
		return container.Invoke(func(config *Config) {
			flagSet.DurationVar(
				&config.Expiration,
				ExpirationFieldName,
				ExpirationDefault,
				"default data retention time",
			)

			flagSet.DurationVar(
				&config.CleanupInterval,
				CleanupIntervalFieldName,
				CleanupIntervalDefault,
				"period for cleaning the cache from 'rotten' data",
			)
		})
	}),
	Run: app.Run(func(container container.Container) error {
		return container.Invoke(func(
			cache *ReConfiguration,
			reConfiguration reConfiguration.ReConfiguration,
			informer logger.Informer,
			config *Config,
		) {
			reConfiguration.Registration(cache)
			informer.Info("cache.app: registration in the reConfigurator")
		})
	}),
}

Functions

func New

func New(config *Config, informer logger.Informer) *goCache.Cache

func NewWithConfigurator

func NewWithConfigurator(configurator configurator.Configurator, config *Config, informer logger.Informer) *goCache.Cache

Types

type Cache

type Cache interface {
	Set(k string, x interface{}, d time.Duration)
	SetDefault(k string, x interface{})
	Add(k string, x interface{}, d time.Duration) error
	Replace(k string, x interface{}, d time.Duration) error
	Get(k string) (interface{}, bool)
	GetWithExpiration(k string) (interface{}, time.Time, bool)
	Increment(k string, n int64) error
	IncrementFloat(k string, n float64) error
	IncrementInt(k string, n int) (int, error)
	IncrementInt8(k string, n int8) (int8, error)
	IncrementInt16(k string, n int16) (int16, error)
	IncrementInt32(k string, n int32) (int32, error)
	IncrementInt64(k string, n int64) (int64, error)
	IncrementUint(k string, n uint) (uint, error)
	IncrementUintptr(k string, n uintptr) (uintptr, error)
	IncrementUint8(k string, n uint8) (uint8, error)
	IncrementUint16(k string, n uint16) (uint16, error)
	IncrementUint32(k string, n uint32) (uint32, error)
	IncrementUint64(k string, n uint64) (uint64, error)
	IncrementFloat32(k string, n float32) (float32, error)
	IncrementFloat64(k string, n float64) (float64, error)
	Decrement(k string, n int64) error
	DecrementFloat(k string, n float64) error
	DecrementInt(k string, n int) (int, error)
	DecrementInt8(k string, n int8) (int8, error)
	DecrementInt16(k string, n int16) (int16, error)
	DecrementInt32(k string, n int32) (int32, error)
	DecrementInt64(k string, n int64) (int64, error)
	DecrementUint(k string, n uint) (uint, error)
	DecrementUintptr(k string, n uintptr) (uintptr, error)
	DecrementUint8(k string, n uint8) (uint8, error)
	DecrementUint16(k string, n uint16) (uint16, error)
	DecrementUint32(k string, n uint32) (uint32, error)
	DecrementUint64(k string, n uint64) (uint64, error)
	DecrementFloat32(k string, n float32) (float32, error)
	DecrementFloat64(k string, n float64) (float64, error)
	Delete(k string)
	DeleteExpired()
	OnEvicted(f func(string, interface{}))
	Save(w io.Writer) (err error)
	SaveFile(fname string) error
	Load(r io.Reader) error
	LoadFile(fname string) error
	Items() map[string]goCache.Item
	ItemCount() int
	Flush()
}

type Config

type Config struct {
	Expiration      time.Duration
	CleanupInterval time.Duration
}

func Configuration

func Configuration(config *Config, configurator configurator.Configurator) *Config

func NewConfig

func NewConfig() *Config

type ReConfiguration

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

func NewReConfiguration

func NewReConfiguration(informer logger.Informer, config *Config) *ReConfiguration

func NewReConfigurationWithConfigurator

func NewReConfigurationWithConfigurator(informer logger.Informer, config *Config, configurator configurator.Configurator) *ReConfiguration

func (*ReConfiguration) Add

func (reConfiguration *ReConfiguration) Add(k string, x interface{}, d time.Duration) error

func (*ReConfiguration) Cache

func (reConfiguration *ReConfiguration) Cache() *goCache.Cache

func (*ReConfiguration) Decrement

func (reConfiguration *ReConfiguration) Decrement(k string, n int64) error

func (*ReConfiguration) DecrementFloat

func (reConfiguration *ReConfiguration) DecrementFloat(k string, n float64) error

func (*ReConfiguration) DecrementFloat32

func (reConfiguration *ReConfiguration) DecrementFloat32(k string, n float32) (float32, error)

func (*ReConfiguration) DecrementFloat64

func (reConfiguration *ReConfiguration) DecrementFloat64(k string, n float64) (float64, error)

func (*ReConfiguration) DecrementInt

func (reConfiguration *ReConfiguration) DecrementInt(k string, n int) (int, error)

func (*ReConfiguration) DecrementInt16

func (reConfiguration *ReConfiguration) DecrementInt16(k string, n int16) (int16, error)

func (*ReConfiguration) DecrementInt32

func (reConfiguration *ReConfiguration) DecrementInt32(k string, n int32) (int32, error)

func (*ReConfiguration) DecrementInt64

func (reConfiguration *ReConfiguration) DecrementInt64(k string, n int64) (int64, error)

func (*ReConfiguration) DecrementInt8

func (reConfiguration *ReConfiguration) DecrementInt8(k string, n int8) (int8, error)

func (*ReConfiguration) DecrementUint

func (reConfiguration *ReConfiguration) DecrementUint(k string, n uint) (uint, error)

func (*ReConfiguration) DecrementUint16

func (reConfiguration *ReConfiguration) DecrementUint16(k string, n uint16) (uint16, error)

func (*ReConfiguration) DecrementUint32

func (reConfiguration *ReConfiguration) DecrementUint32(k string, n uint32) (uint32, error)

func (*ReConfiguration) DecrementUint64

func (reConfiguration *ReConfiguration) DecrementUint64(k string, n uint64) (uint64, error)

func (*ReConfiguration) DecrementUint8

func (reConfiguration *ReConfiguration) DecrementUint8(k string, n uint8) (uint8, error)

func (*ReConfiguration) DecrementUintptr

func (reConfiguration *ReConfiguration) DecrementUintptr(k string, n uintptr) (uintptr, error)

func (*ReConfiguration) Delete

func (reConfiguration *ReConfiguration) Delete(k string)

func (*ReConfiguration) DeleteExpired

func (reConfiguration *ReConfiguration) DeleteExpired()

func (*ReConfiguration) Flush

func (reConfiguration *ReConfiguration) Flush()

func (*ReConfiguration) Get

func (reConfiguration *ReConfiguration) Get(k string) (interface{}, bool)

func (*ReConfiguration) GetWithExpiration

func (reConfiguration *ReConfiguration) GetWithExpiration(k string) (interface{}, time.Time, bool)

func (*ReConfiguration) Increment

func (reConfiguration *ReConfiguration) Increment(k string, n int64) error

func (*ReConfiguration) IncrementFloat

func (reConfiguration *ReConfiguration) IncrementFloat(k string, n float64) error

func (*ReConfiguration) IncrementFloat32

func (reConfiguration *ReConfiguration) IncrementFloat32(k string, n float32) (float32, error)

func (*ReConfiguration) IncrementFloat64

func (reConfiguration *ReConfiguration) IncrementFloat64(k string, n float64) (float64, error)

func (*ReConfiguration) IncrementInt

func (reConfiguration *ReConfiguration) IncrementInt(k string, n int) (int, error)

func (*ReConfiguration) IncrementInt16

func (reConfiguration *ReConfiguration) IncrementInt16(k string, n int16) (int16, error)

func (*ReConfiguration) IncrementInt32

func (reConfiguration *ReConfiguration) IncrementInt32(k string, n int32) (int32, error)

func (*ReConfiguration) IncrementInt64

func (reConfiguration *ReConfiguration) IncrementInt64(k string, n int64) (int64, error)

func (*ReConfiguration) IncrementInt8

func (reConfiguration *ReConfiguration) IncrementInt8(k string, n int8) (int8, error)

func (*ReConfiguration) IncrementUint

func (reConfiguration *ReConfiguration) IncrementUint(k string, n uint) (uint, error)

func (*ReConfiguration) IncrementUint16

func (reConfiguration *ReConfiguration) IncrementUint16(k string, n uint16) (uint16, error)

func (*ReConfiguration) IncrementUint32

func (reConfiguration *ReConfiguration) IncrementUint32(k string, n uint32) (uint32, error)

func (*ReConfiguration) IncrementUint64

func (reConfiguration *ReConfiguration) IncrementUint64(k string, n uint64) (uint64, error)

func (*ReConfiguration) IncrementUint8

func (reConfiguration *ReConfiguration) IncrementUint8(k string, n uint8) (uint8, error)

func (*ReConfiguration) IncrementUintptr

func (reConfiguration *ReConfiguration) IncrementUintptr(k string, n uintptr) (uintptr, error)

func (*ReConfiguration) ItemCount

func (reConfiguration *ReConfiguration) ItemCount() int

func (*ReConfiguration) Items

func (reConfiguration *ReConfiguration) Items() map[string]goCache.Item

func (*ReConfiguration) Load

func (reConfiguration *ReConfiguration) Load(r io.Reader) error

func (*ReConfiguration) LoadFile

func (reConfiguration *ReConfiguration) LoadFile(fname string) error

func (*ReConfiguration) OnEvicted

func (reConfiguration *ReConfiguration) OnEvicted(f func(string, interface{}))

func (*ReConfiguration) ReConfiguration

func (reConfiguration *ReConfiguration) ReConfiguration(c configurator.Configurator) error

func (*ReConfiguration) Replace

func (reConfiguration *ReConfiguration) Replace(k string, x interface{}, d time.Duration) error

func (*ReConfiguration) Save

func (reConfiguration *ReConfiguration) Save(w io.Writer) (err error)

func (*ReConfiguration) SaveFile

func (reConfiguration *ReConfiguration) SaveFile(fname string) error

func (*ReConfiguration) Set

func (reConfiguration *ReConfiguration) Set(k string, x interface{}, d time.Duration)

func (*ReConfiguration) SetDefault

func (reConfiguration *ReConfiguration) SetDefault(k string, x interface{})

Jump to

Keyboard shortcuts

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