jdlehman / omni-cache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OmniCache

OmniCache is a flexible cache API with pluggable persistence layers (in-memory, Redis, etc). Any persistence layer that implements the Cache and Conn interfaces from panoplymedia/cache can be used with this package.

Sample Usage

type MyData struct {
  Value int
}

// called when Fetch doesnt find data in the cache
func (m MyData) CacheMiss(key string) ([]byte, error) {
  return []byte("hydrated"), nil
}

// where `conn` is a cache.Conn
c := localcache.New(conn)
err := c.Set([]byte("key"), []byte("value"))
if err != nil {
  fmt.Println(err)
}
b, err := c.Get([]byte("key"))
if err != nil {
  fmt.Println(err)
}

d := MyData{}
// returns data from the cache or calls `CacheMiss` for `MyData`
b, err = c.Fetch([]byte("miss"), d)

Compatible Persistence Layers

Create New Persistence Layer

  • Name repository omni-cache-<persistence-layer>
  • Implement Cache and Conn interfaces from panoplymedia/cache
  • Add link to this README

About

License:MIT License


Languages

Language:Go 100.0%