rediscache

package
Version: v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

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

Example (HowToUse)
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)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

New Redis cache middleware creates & returns.

Types

type CacheOption added in v0.15.0

type CacheOption interface {
	Apply(*cacheHandler)
}

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

func WithCacheKey added in v0.15.0

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 added in v0.15.0

func WithExcludeKinds(kinds ...string) CacheOption

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

func WithExpireDuration added in v0.15.0

func WithExpireDuration(d time.Duration) CacheOption

WithExpireDuration creates a ClientOption to expire at a specified time.

func WithIncludeKinds added in v0.15.0

func WithIncludeKinds(kinds ...string) CacheOption

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

func WithKeyFilter added in v0.15.0

func WithKeyFilter(f storagecache.KeyFilter) CacheOption

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

func WithLogger added in v0.15.0

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

WithLogger creates a ClientOption that uses the specified logger.

Jump to

Keyboard shortcuts

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