Documentation
¶
Index ¶
Constants ¶
View Source
const ( HostsFieldName = "cache.memcached.hosts" MaxIdleConnections = "cache.memcached.maxIdleConnections" TimeoutFieldName = "cache.memcached.timeout" MaxIdleConnectionsDefault = memcache.DefaultMaxIdleConns TimeoutDefault = memcache.DefaultTimeout )
Variables ¶
View Source
var Component = &component.Component{ Init: component.StepFunc(func(container container.Container) error { return container.Provides( NewConfig, NewCache, func(cache *memcache.Client) Cache { return cache }, ) }), BindFlags: component.BindFlags(func(flagSet flag.FlagSet, container container.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: component.StepFunc(func(container container.Container) error { return container.Invoke(Configuration) }), }
Component is a ready-to-use Compogo component that provides a Memcached client. It automatically:
- Registers Config and Client in the DI container
- Adds command-line flags for Memcached configuration
- Configures the client during Configuration phase
- Provides the client as both *memcache.Client and Cache interface
Usage:
compogo.WithComponents(
memcached.Component,
// ... your service components
)
Then in your service:
type Service struct {
cache memcached.Cache // or *memcache.Client
}
View Source
var HostsDefault = []string{"localhost:11211"}
Functions ¶
func NewCache ¶
NewCache creates a new Memcached client instance. It initializes the underlying gomemcache client with the configured hosts, connection pool size, and timeout settings.
The informer is used to log the configuration for debugging purposes. Returns a configured memcache.Client ready for use.
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 defines the complete interface for Memcached operations. It mirrors the full API of bradfitz/gomemcache to provide maximum flexibility.
The interface includes methods for:
- Basic operations: Set, Get, Delete
- Atomic operations: Increment, Decrement, CompareAndSwap
- Multi-key operations: GetMulti
- Batch operations: DeleteAll, FlushAll
- Connection management: Ping
- Expiration management: Touch
- Data modification: Append, Prepend
type Config ¶
func Configuration ¶
func Configuration(config *Config, configurator configurator.Configurator) *Config
Click to show internal directories.
Click to hide internal directories.