Skip to content

panoplymedia/omni-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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