cache

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: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Кэш.

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

Список доступных драйверов:
Объект конфигурации.
type Config struct {
	Driver     string
	Expiration time.Duration
}

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

Поле Описание Значение по умолчанию Доступные значения
Driver Имя драйвера кэширующей системы, который следует использовать, этот параметр может быть передан одним из 3-х методов:
- флаг командной строки --cache.driver
- переменная окружения CACHE_DRIVER
- значение в конфиг файле cache.driver
app - app - Gocache;
- memcached - Memcached;
- redis - Redis.
Expiration Время хранения записи по умолчанию, этот параметр может быть передан одним из 3-х методов:
- флаг командной строки --cache.expiration
- переменная окружения CACHE_EXPIRATION
- значение в конфиг файле cache.expiration
5 минут

Documentation

Index

Constants

View Source
const (
	DriverFieldName     = "cache.driver"
	ExpirationFieldName = "cache.expiration"

	GoCacheDriver   = "app"
	RedisDriver     = "redis"
	MemcachedDriver = "memcached"

	DriverDefault     = GoCacheDriver
	ExpirationDefault = 5 * time.Minute
)

Variables

View Source
var Component = &app.Component{
	Dependencies: app.Components{
		logger.Component,
		configurator.Component,
		reConfiguration.Component,
		gocache.Component,
		memcached.Component,
		redis.Component,
	},
	Constructor: app.Constructor(func(container container.Container) error {
		return container.Provides(
			NewConfig,
			NewReConfigurationWithConfigurator,
			func(reConfiguration *ReConfiguration[[]byte]) cache.CacheInterface[[]byte] { return reConfiguration },
		)
	}),
	BindFlags: app.BindFlags(func(flagSet *pflag.FlagSet, container container.Container) error {
		return container.Invoke(func(config *Config) {
			flagSet.StringVar(&config.Driver, DriverFieldName, DriverDefault, fmt.Sprintf(
				"cache driver. Available drivers: "+
					"%s - stores data in application memory; "+
					"%s - stores data in redis; "+
					"%s - stores data in memcached.",
				GoCacheDriver,
				RedisDriver,
				MemcachedDriver,
			))

			flagSet.DurationVar(&config.Expiration, ExpirationFieldName, ExpirationDefault, "default data retention time")
		})
	}),
	Run: app.Run(func(container container.Container) error {
		return container.Invoke(func(
			cache *ReConfiguration[[]byte],
			reConfiguration reConfiguration.ReConfiguration,
			informer logger.Informer,
			config *Config,
		) {
			reConfiguration.Registration(cache)
			informer.Info("cache: registration in the reConfigurator")
		})
	}),
}

Functions

func New

func New[T any](config *Config, appConfig *app.Config, informer logger.Informer, container container.Container) (cache.CacheInterface[T], error)

func NewWithConfigurator

func NewWithConfigurator[T any](
	config *Config,
	configurator configurator.Configurator,
	appConfig *app.Config,
	informer logger.Informer,
	container container.Container,
) (cache.CacheInterface[T], error)

Types

type Config

type Config struct {
	Driver     string
	Expiration time.Duration
}

func Configuration

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

func NewConfig

func NewConfig() *Config

type ReConfiguration

type ReConfiguration[T any] struct {
	// contains filtered or unexported fields
}

func NewReConfiguration

func NewReConfiguration(informer logger.Informer, appConfig *app.Config, container container.Container, config *Config) (*ReConfiguration[[]byte], error)

func NewReConfigurationWithConfigurator

func NewReConfigurationWithConfigurator(informer logger.Informer, appConfig *app.Config, container container.Container, config *Config, configurator configurator.Configurator) (*ReConfiguration[[]byte], error)

func (*ReConfiguration[T]) Cache

func (reConfiguration *ReConfiguration[T]) Cache() cache.CacheInterface[T]

func (*ReConfiguration[T]) Clear

func (reConfiguration *ReConfiguration[T]) Clear(ctx context.Context) error

func (*ReConfiguration[T]) Delete

func (reConfiguration *ReConfiguration[T]) Delete(ctx context.Context, key any) error

func (*ReConfiguration[T]) Get

func (reConfiguration *ReConfiguration[T]) Get(ctx context.Context, key any) (T, error)

func (*ReConfiguration[T]) GetType

func (reConfiguration *ReConfiguration[T]) GetType() string

func (*ReConfiguration[T]) Invalidate

func (reConfiguration *ReConfiguration[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error

func (*ReConfiguration[T]) ReConfiguration

func (reConfiguration *ReConfiguration[T]) ReConfiguration(c configurator.Configurator) error

func (*ReConfiguration[T]) Set

func (reConfiguration *ReConfiguration[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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