cache

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: Apache-2.0 Imports: 8 Imported by: 11

README

go-cache

go-cache is a simple cache dependency system on-top of the famous redigo package

License Report Codacy Badge Build Status standard-readme compliant Release GoDoc

Table of Contents

Installation

go-cache requires a supported release of Go and dep.

$ go get -u github.com/mrz1836/go-cache

Updating dependencies in go-cache:

$ cd ../go-cache
$ dep ensure -update -v
Package Dependencies

Documentation

You can view the generated documentation here.

Features
  • Cache Dependencies Between Keys
  • Connect via URL
  • Better Pool Management & Creation

Examples & Tests

All unit tests and examples run via Travis CI and uses Go version 1.12.x. View the deployment configuration file.

Run all tests (including integration tests)

$ cd ../go-cache
$ go test ./... -v

Run tests (excluding integration tests)

$ cd ../go-cache
$ go test ./... -v -test.short

View and run the examples:

$ cd ../go-cache/examples
$ go run examples.go

Benchmarks

Run the Go benchmarks:

$ cd ../go-cache
$ go test -bench . -benchmem

Code Standards

Read more about this Go project's code standards.

Usage

View the examples

Basic implementation:

package main

import (

)

func main() {

}

Maintainers

@MrZ1836 | @kayleg

Contributing

This project uses Gary Burd's Redigo package.

View the contributing guidelines and follow the code of conduct.

Support the development of this project 🙏

Donate

License

License

Documentation

Overview

Package cache is a cache dependency management on-top of the famous redigo package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(url string, maxActiveConnections, idleConnections, maxConnLifetime, idleTimeout int) error

Connect creates a new connection pool connected to the specified url

func ConnectToURL

func ConnectToURL(urlString string) (c redis.Conn, err error)

ConnectToURL connects via REDIS_URL Source: github.com/soveran/redisurl URL Format: redis://localhost:6379

func DestroyCache

func DestroyCache() (err error)

DestroyCache will flush the entire redis server. It only removes keys, not scripts

func DidRegisterKillByDependencyScript

func DidRegisterKillByDependencyScript() bool

DidRegisterKillByDependencyScript returns true if the script has a sha from redis

func Disconnect

func Disconnect()

Disconnect closes the connection pool

func Exists

func Exists(key string) (bool, error)

Exists checks if a key is present or not

func Expire

func Expire(key string, duration time.Duration) (err error)

Expire sets the expiration for a given key

func Get

func Get(key string) (string, error)

Get gets a key from redis

func GetAllKeys

func GetAllKeys() (keys []string, err error)

GetAllKeys returns a []string of keys

func GetBytes

func GetBytes(key string) ([]byte, error)

GetBytes gets a key from redis in bytes

func GetConnection

func GetConnection() redis.Conn

GetConnection will return a connection from the pool. The connection must be closed when done with use to return it to the pool

func GetOrSetWithExpirationGob

func GetOrSetWithExpirationGob(key string, fn GobCacheCreator, duration time.Duration, dependencies ...string) (data []byte, err error)

GetOrSetWithExpirationGob will return the cached value for the key or use the GobCacheCreator to create and insert the value into the cache. If the expiration time is set to a value greater than zero, the key will be set to expire in the provided duration

func GetPool

func GetPool() *redis.Pool

GetPool returns the underlying connection pool

func GetStringSlice

func GetStringSlice(key string) (destination []string, err error)

GetStringSlice returns a []string stored in redis

func HashGet

func HashGet(hash, key string) (string, error)

HashGet gets a key from redis via hash

func HashMapGet

func HashMapGet(hashName string, keys ...interface{}) ([]string, error)

HashMapGet gets values from a hash map for corresponding keys

func HashMapSet

func HashMapSet(hashName string, pairs [][2]interface{}, dependencies ...string) (err error)

HashMapSet will set the hashKey to the value in the specified hashName and link a reference to each dependency for the entire hash

func HashMapSetExp

func HashMapSetExp(hashName string, pairs [][2]interface{}, ttl time.Duration, dependencies ...string) (err error)

HashMapSetExp will set the hashKey to the value in the specified hashName and link a reference to each dependency for the entire hash

func HashSet

func HashSet(hashName, hashKey string, value interface{}, dependencies ...string) (err error)

HashSet will set the hashKey to the value in the specified hashName and link a reference to each dependency for the entire hash

func KillByDependency

func KillByDependency(keys ...string) (total int, err error)

KillByDependency removes all keys which are listed as depending on the key(s)

func RegisterScript

func RegisterScript(script string) (sha string, err error)

RegisterScript register a script

func RegisterScripts

func RegisterScripts() (err error)

RegisterScripts register all scripts

func Set

func Set(key string, value interface{}, dependencies ...string) (err error)

Set will set the key in redis and keep a reference to each dependency value can be both a string or []byte

func SetAdd

func SetAdd(setName, member interface{}, dependencies ...string) (err error)

SetAdd will add the member to the Set and link a reference to each dependency for the entire Set

func SetExp

func SetExp(key string, value interface{}, ttl time.Duration, dependencies ...string) (err error)

SetExp will set the key in redis and keep a reference to each dependency value can be both a string or []byte

func SetIsMember

func SetIsMember(set, member interface{}) (bool, error)

SetIsMember returns if the member is part of the set

func SetRemoveMember

func SetRemoveMember(set, member interface{}) (err error)

SetRemoveMember removes the member from the set

Types

type GobCacheCreator

type GobCacheCreator func() ([]byte, error)

GobCacheCreator can be used to generate the content to store. If the content is not found, the creator will be invoked and the result will be stored and returned

Jump to

Keyboard shortcuts

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