cacher

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: BSD-2-Clause Imports: 10 Imported by: 0

README

Consul leader election Build Status codecov

This package provides dependency cache

How to use

See example

See documentation

It is safe to use in multiple goroutines

Supports:

TODO:

  • Memory
  • Memcached
  • MongoDB

We use go-redis/redis

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dependency

type Dependency struct {
	Key   string `json:"k"`
	Value int64  `json:"v"`
}

Dependency is a dependency data

func (Dependency) GetKey

func (d Dependency) GetKey() string

GetKey return key of dependency counter

func (Dependency) GetValue

func (d Dependency) GetValue() int64

GetValue return value of dependency counter

type ICache

type ICache interface {
	//Set sets value of key with ttl and dependencies
	Set(key, value string, ttl *time.Duration, dependency ...IDependency) error
	//Get returns value of key
	Get(key string) (value string, dependencies []Dependency, ok bool, err error)
	//Del delete key from cache
	Del(key string) error
	//IncrDependency increment dependency counter
	IncrDependency(ttl *time.Duration, depKey ...string) error
	//GetDependencies returns dependency by key
	GetDependencies(depKey ...string) ([]Dependency, error)
	//SetDependency  sets value of dependency
	SetDependency(ttl *time.Duration, dependencies ...IDependency) error
	//Clear clear all cache
	Clear() error
}

ICache is an abstract cache, which describe methods

func NewRedis

func NewRedis(conf *RedisConfig) (ICache, error)

NewRedis creat structure which implements ICache interface

type IDependency

type IDependency interface {
	//GetKey return key of dependency counter
	GetKey() string
	//GetValue return value of dependency counter
	GetValue() int64
}

IDependency is an abstract dependency data

type Redis

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

Redis is implements of ICache methods

func (*Redis) Clear

func (r *Redis) Clear() error

Clear invalidate all cache

func (*Redis) Del

func (r *Redis) Del(key string) error

Del delete key from cache

func (*Redis) Get

func (r *Redis) Get(key string) (value string, dependencies []Dependency, ok bool, err error)

Get returns value of key

func (*Redis) GetDependencies

func (r *Redis) GetDependencies(depKey ...string) ([]Dependency, error)

GetDependencies returns dependency by key

func (*Redis) IncrDependency

func (r *Redis) IncrDependency(ttl *time.Duration, depKey ...string) error

IncrDependency increment dependency counter

func (*Redis) Set

func (r *Redis) Set(key, value string, ttl *time.Duration, dependency ...IDependency) error

Set sets value of key with ttl and dependencies

func (*Redis) SetDependency

func (r *Redis) SetDependency(ttl *time.Duration, dependency ...IDependency) error

SetDependency sets value of dependency

type RedisConfig

type RedisConfig struct {
	Client             redis.UniversalClient
	KeyPrefix          string
	DependencyPrefix   string
	LogPrefix          string
	EnableDataCompress bool
}

RedisConfig structure is used for configure redis based cache

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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