datastore: go.mercari.io/datastore/dsmiddleware/rediscache Index | Examples | Files

package rediscache

import "go.mercari.io/datastore/dsmiddleware/rediscache"

Package rediscache handles Put, Get etc to Datastore and provides caching by Redis. How the cache is used is explained in the storagecache package's document.

Related document.

https://godoc.org/go.mercari.io/datastore/dsmiddleware/storagecache

Code:

package main

import (
    "context"
    "net"
    "time"

    "github.com/gomodule/redigo/redis"
    "go.mercari.io/datastore/clouddatastore"
    "go.mercari.io/datastore/dsmiddleware/rediscache"
    "go.mercari.io/datastore/internal/testutils"
)

const redisAddress = ":6379"

func main() {
    ctx := context.Background()
    client, err := clouddatastore.FromContext(ctx)
    if err != nil {
        panic(err)
    }
    defer client.Close()
    defer testutils.CleanUpAllEntities(ctx, client)

    dial, err := net.Dial("tcp", redisAddress)
    if err != nil {
        panic(err)
    }
    defer dial.Close()
    conn := redis.NewConn(dial, 100*time.Millisecond, 100*time.Millisecond)
    defer conn.Close()

    mw := rediscache.New(conn)
    client.AppendMiddleware(mw)
}

Index

Examples

Package Files

doc.go option.go rediscache.go

func New Uses

func New(conn redis.Conn, opts ...CacheOption) interface {
    datastore.Middleware
    storagecache.Storage
}

New Redis cache middleware creates & returns.

type CacheOption Uses

type CacheOption interface {
    Apply(*cacheHandler)
}

A CacheOption is an cache option for a Redis cache middleware.

func WithCacheKey Uses

func WithCacheKey(f func(key datastore.Key) string) CacheOption

WithCacheKey creates a ClientOption that specifies how to generate a cache key from datastore.Key.

func WithExcludeKinds Uses

func WithExcludeKinds(kinds ...string) CacheOption

WithExcludeKinds creates a ClientOption that selects the Kind unspecified as the cache target.

func WithExpireDuration Uses

func WithExpireDuration(d time.Duration) CacheOption

WithExpireDuration creates a ClientOption to expire at a specified time.

func WithIncludeKinds Uses

func WithIncludeKinds(kinds ...string) CacheOption

WithIncludeKinds creates a ClientOption that selects the Kind specified as the cache target.

func WithKeyFilter Uses

func WithKeyFilter(f storagecache.KeyFilter) CacheOption

WithKeyFilter creates a ClientOption that selects the Keys specified as the cache target.

func WithLogger Uses

func WithLogger(logf func(ctx context.Context, format string, args ...interface{})) CacheOption

WithLogger creates a ClientOption that uses the specified logger.

Package rediscache imports 8 packages (graph). Updated 2018-06-23. Refresh now. Tools for package owners.