示例#1
0
文件: ybc.go 项目: inthecloud247/ybc
// The same as Cache.Set(), but additionally returns item object associated
// with just addded item.
//
// The returned item must be closed with item.Close() call!
func (cache *Cache) SetItem(key []byte, value []byte, ttl time.Duration) (item *Item, err error) {
	cache.dg.CheckLive()
	item = acquireItem()
	k := newKey(key)
	v := newValue(value, ttl)
	if C.ybc_item_set_item(cache.ctx(), item.ctx(), &k, &v) == 0 {
		releaseItem(item)
		err = ErrNoSpace
		return
	}
	item.dg.Init()
	return
}
示例#2
0
文件: ybc.go 项目: rjmcguire/ybc
// The same as Cache.Set(), but additionally returns item object associated
// with just addded item.
//
// The returned item must be closed with item.Close() call!
func (cache *Cache) SetItem(key []byte, value []byte, ttl time.Duration) (item *Item, err error) {
	cache.dg.CheckLive()
	item = acquireItem()
	var k C.struct_ybc_key
	initKey(&k, key)
	var v C.struct_ybc_value
	initValue(&v, value, ttl)
	if C.ybc_item_set_item(cache.ctx(), item.ctx(), &k, &v) == 0 {
		releaseItem(item)
		err = ErrNoSpace
		return
	}
	item.dg.Init()
	return
}