memcache

package module
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package memcache provides a Memcache Client implementation of the driver.Cache interface. It uses the memcache library to interact with a Memcache Client.

URL Format:

The URL should have the following format:

memcache://<host1>:<port1>,<host2>:<port2>,...,<hostN>:<portN>

Each <host>:<port> pair corresponds to the Memcache Client node.

Usage

import (
    "context"
    "log"
    "net/url"

    "github.com/bartventer/gocache"
    _ "github.com/bartventer/gocache/memcache"
)

func main() {
    ctx := context.Background()
    urlStr := "memcache://localhost:11211"
    c, err := cache.OpenCache(ctx, urlStr)
    if err != nil {
        log.Fatalf("Failed to initialize cache: %v", err)
    }
    // ... use c with the cache.Cache interface
}

You can create a Memcache cache with New:

import (
    "context"
    "log"
    "net/url"

    "github.com/bartventer/gocache/memcache"
)

func main() {
    ctx := context.Background()
    c := memcache.New[string](ctx, &memcache.Options{
		Addrs: []string{"localhost:11211"},
	})
    // ... use c with the cache.Cache interface
}

Limitations

Please note that due to the limitations of the Memcache protocol, pattern matching operations are not supported. This includes the cache.Cache Count and DelKeys methods, which will return a cache.ErrPatternMatchingNotSupported error if called.

Index

Constants

View Source
const Scheme = "memcache"

Scheme is the cache scheme for Memcache.

Variables

This section is empty.

Functions

func New

func New[K driver.String](ctx context.Context, opts *Options) *memcacheCache[K]

New returns a new Memcache cache implementation.

Types

type Options added in v0.8.0

type Options struct {
	// Addrs is the list of Memcache server addresses.
	Addrs []string
}

Options is the configuration for the Memecache cache.

Jump to

Keyboard shortcuts

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