项目作者: juntaki

项目描述 :
Transparent cache and distributed commit to key-value store
高级语言: Go
项目地址: git://github.com/juntaki/transparent.git
创建时间: 2016-11-16T14:14:02Z
项目社区:https://github.com/juntaki/transparent

开源协议:MIT License

下载


transparent

Transparent cache and distributed commit to key-value store written in Go.

Build Status
Coverage Status
Go Report Card
GoDoc

Documentation

Installation

  1. go get github.com/juntaki/transparent

Basic usage

First, create layers and stack them with Stack.Stack().
This example adds LRU memory cache and filesystem cache to dummy source layer.

  1. cacheLayer1, _ := lru.NewCache(10, 100)
  2. cacheLayer2 := filesystem.NewCache(10, "/tmp")
  3. sourceLayer := test.NewSource(10)
  4. stack := transparent.NewStack()
  5. stack.Stack(sourceLayer)
  6. stack.Stack(cacheLayer2)
  7. stack.Stack(cacheLayer1)

If you manipulate the Stack, the value will be transmitted from top layer to the bottom layer transparently.

  1. stack.Set("key", []byte("value"))
  2. stack.Sync()
  3. // value, _ = cacheLayer1.Get("key") // "value"
  4. // value, _ = cacheLayer2.Get("key") // "value"
  5. // value, _ = sourceLayer.Get("key") // "value"
  6. value, _ := stack.Get("key")
  7. fmt.Printf("%s\n", value) // "value"

For details, please refer to [Godoc] (https://godoc.org/github.com/juntaki/transparent).