Example #1
0
// 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
}
Example #2
0
// 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)
}
Example #3
0
// 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
}
Example #4
0
// 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
}