memcache

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package memcache implements a memcache adapter for github.com/hamba/pkg/cache.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memcache

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

Memcache is a memcache adapter.

func New

func New(uri string, opts ...OptsFunc) *Memcache

New create a new Memcache instance.

Example
package main

import (
	"context"
	"time"

	"github.com/hamba/cache/v2/memcache"
)

func main() {
	c := memcache.New("localhost:11211", memcache.WithIdleConns(10), memcache.WithTimeout(10*time.Millisecond))

	i := c.Get(context.Background(), "foobar")
	if i.Err != nil {
		// Handle error
	}

	_, _ = i.Float64()
}
Output:

func (Memcache) Add

func (c Memcache) Add(_ context.Context, key string, value interface{}, expire time.Duration) error

Add sets the item in the cache, but only if the key does not already exist.

func (Memcache) Dec

func (c Memcache) Dec(_ context.Context, key string, value uint64) (int64, error)

Dec decrements a key by the value.

func (Memcache) Delete

func (c Memcache) Delete(_ context.Context, key string) error

Delete deletes the item with the given key.

func (Memcache) Get

func (c Memcache) Get(_ context.Context, key string) cache.Item

Get gets the item for the given key.

func (Memcache) GetMulti

func (c Memcache) GetMulti(_ context.Context, keys ...string) ([]cache.Item, error)

GetMulti gets the items for the given keys.

func (Memcache) Inc

func (c Memcache) Inc(_ context.Context, key string, value uint64) (int64, error)

Inc increments a key by the value.

func (Memcache) Replace

func (c Memcache) Replace(_ context.Context, key string, value interface{}, expire time.Duration) error

Replace sets the item in the cache, but only if the key already exists.

func (Memcache) Set

func (c Memcache) Set(_ context.Context, key string, value interface{}, expire time.Duration) error

Set sets the item in the cache.

type OptsFunc

type OptsFunc func(*memcache.Client)

OptsFunc represents an configuration function for Memcache.

func WithIdleConns

func WithIdleConns(size int) OptsFunc

WithIdleConns configures the Memcache max idle connections.

func WithTimeout

func WithTimeout(timeout time.Duration) OptsFunc

WithTimeout configures the Memcache read and write timeout.

Jump to

Keyboard shortcuts

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