// NewCache allocates and initializes a new Cache. // func NewCache(path string) (*Cache, error) { _, err := kvson.NewKVSON(path) if err != nil { return nil, err } return &Cache{Path: path}, nil }
// IsCached returns if a key is cached or not func (c *Cache) IsCached(key string) bool { kv, err := kvson.NewKVSON(c.Path) if err != nil { return false } return kv.Exists(key) }
// Load gets the content from the cache by key func (c *Cache) Load(key string, value interface{}) error { kv, err := kvson.NewKVSON(c.Path) if err != nil { return err } err = kv.Get(key, &value) return err }
// Save caches the key value pair func (c *Cache) Save(key string, payload interface{}) error { kv, err := kvson.NewKVSON(c.Path) if err != nil { return err } err = kv.Put(key, payload) return err }