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.
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)
- Name repository
omni-cache-<persistence-layer>
- Implement
Cache
andConn
interfaces from panoplymedia/cache - Add link to this README