Documentation
¶
Index ¶
Constants ¶
View Source
const ( // HostsFieldName хосты Memcached HostsFieldName = "cache.memcached.hosts" // MaxIdleConnections максимальное число простаивающих соединений MaxIdleConnections = "cache.memcached.maxIdleConnections" // TimeoutFieldName таймаут операций TimeoutFieldName = "cache.memcached.timeout" )
Variables ¶
View Source
var ( HostsDefault = []string{"localhost:11211"} MaxIdleConnectionsDefault = uint16(memcache.DefaultMaxIdleConns) TimeoutDefault = memcache.DefaultTimeout )
View Source
var Component = compogo.Component{ Init: compogo.StepFunc(func(container compogo.Container) error { return container.Provides( NewConfig, NewCache, func(cache *memcache.Client) Cache { return cache }, ) }), BindFlags: compogo.BindFlags(func(flagSet flag.FlagSet, container compogo.Container) error { return container.Invoke(func(config *Config) { flagSet.StringSliceVar(&config.Hosts, HostsFieldName, HostsDefault, "memcached connection hosts") flagSet.Uint16Var(&config.MaxIdleConnections, MaxIdleConnections, MaxIdleConnectionsDefault, "maximum number of idle connections") flagSet.DurationVar(&config.Timeout, TimeoutFieldName, TimeoutDefault, "socket read/write timeout") }) }), Configuration: compogo.StepFunc(func(container compogo.Container) error { return container.Invoke(Configuration) }), }
Component — компонент Memcached для Compogo. Регистрирует конфигурацию и клиент в DI-контейнере.
Пример подключения:
app.AddComponents(&memcached.Component)
var client memcached.Cache
container.Invoke(func(c memcached.Cache) { client = c })
client.Set(&memcache.Item{Key: "key", Value: []byte("value")})
Functions ¶
Types ¶
type Cache ¶
type Cache interface {
Add(item *memcache.Item) error
Append(item *memcache.Item) error
CompareAndSwap(item *memcache.Item) error
Decrement(key string, delta uint64) (newValue uint64, err error)
Delete(key string) error
DeleteAll() error
FlushAll() error
Get(key string) (item *memcache.Item, err error)
GetMulti(keys []string) (map[string]*memcache.Item, error)
Increment(key string, delta uint64) (newValue uint64, err error)
Ping() error
Prepend(item *memcache.Item) error
Replace(item *memcache.Item) error
Set(item *memcache.Item) error
Touch(key string, seconds int32) (err error)
}
Cache — интерфейс для работы с Memcached. Предоставляет все методы библиотеки gomemcache.
Поддерживает:
- Базовые операции: Set, Get, Delete
- Атомарные операции: Increment, Decrement, CompareAndSwap
- Множественные операции: GetMulti
- Администрирование: FlushAll, DeleteAll, Ping
- Управление TTL: Touch
type Config ¶
Config содержит конфигурацию Memcached.
func Configuration ¶
func Configuration(config *Config, configurator compogo.Configurator) *Config
Configuration загружает конфигурацию из Configurator. Если значения не заданы, устанавливаются значения по умолчанию.
Click to show internal directories.
Click to hide internal directories.