Skip to content
/ nscache Public

A Go caching framework that supports multiple data source drivers

License

Notifications You must be signed in to change notification settings

no-src/nscache

Repository files navigation

nscache

Build License Go Reference Go Report Card codecov Release

Installation

go get -u github.com/no-src/nscache

Quick Start

Current support following cache

  • memory memory:
  • redis redis:https://127.0.0.1:6379
  • buntdb buntdb:https://:memory: or buntdb:https://buntdb.db
  • etcd etcd:https://127.0.0.1:2379?dial_timeout=5s

For example, init a memory cache, write and read data.

package main

import (
	"time"

	"github.com/no-src/log"
	"github.com/no-src/nscache"
	_ "github.com/no-src/nscache/memory"
)

func main() {
	c, err := nscache.NewCache("memory:")
	if err != nil {
		log.Error(err, "init cache error")
		return
	}
	k := "hello"
	c.Set(k, "world", time.Minute)
	var v string
	if err = c.Get(k, &v); err != nil {
		log.Error(err, "get cache error")
		return
	}
	log.Info("key=%s value=%s", k, v)
}