当前位置: 首页>>代码示例>>Golang>>正文


Golang Cacher.GetDeAsyncItem方法代码示例

本文整理汇总了Golang中github.com/valyala/ybc/bindings/go/ybc.Cacher.GetDeAsyncItem方法的典型用法代码示例。如果您正苦于以下问题:Golang Cacher.GetDeAsyncItem方法的具体用法?Golang Cacher.GetDeAsyncItem怎么用?Golang Cacher.GetDeAsyncItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/valyala/ybc/bindings/go/ybc.Cacher的用法示例。


在下文中一共展示了Cacher.GetDeAsyncItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: processGetDeCmd

func processGetDeCmd(c *bufio.ReadWriter, cache ybc.Cacher, line []byte, scratchBuf *[]byte) bool {
	n := -1

	key := nextToken(line, &n, "key")
	if key == nil {
		return false
	}
	graceDuration, ok := parseMillisecondsToken(line, &n, "graceDuration")
	if !ok {
		return false
	}
	if !expectEof(line, n) {
		return false
	}

	item, err := cache.GetDeAsyncItem(key, graceDuration)
	if err != nil {
		if err == ybc.ErrWouldBlock {
			return writeStr(c.Writer, strWouldBlockCrLf)
		}
		if err == ybc.ErrCacheMiss {
			return writeEndCrLf(c.Writer)
		}
		log.Fatalf("Unexpected error returned by Cache.GetDeAsyncItem(): [%s]", err)
	}
	// do not use defer item.Close() for performance reasons

	ok = writeGetResponseWithEof(c.Writer, key, item, scratchBuf)
	item.Close()
	return ok
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:31,代码来源:server.go

示例2: cGetDeFromCache

func cGetDeFromCache(cache ybc.Cacher, key []byte, etag *uint64, graceDuration time.Duration) (item *ybc.Item, err error) {
	item, err = cache.GetDeAsyncItem(key, graceDuration)
	if err == ybc.ErrCacheMiss || err == ybc.ErrWouldBlock {
		return
	}
	if err != nil {
		log.Fatalf("Unexpected error returned from Cache.GetItem() for key=[%s]: [%s]", key, err)
	}
	defer func() {
		if err != nil {
			item.Close()
		}
	}()

	etagOld := *etag
	if err = binaryRead(item, etag, "etag"); err != nil {
		return
	}
	if etagOld == *etag {
		item.Close()
		item = nil
		return
	}
	return
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:25,代码来源:server.go

示例3: processCgetDeCmd

func processCgetDeCmd(c *bufio.ReadWriter, cache ybc.Cacher, line []byte, scratchBuf *[]byte) bool {
	n := -1

	key := nextToken(line, &n, "key")
	if key == nil {
		return false
	}
	casid, ok := parseUint64Token(line, &n, "casid")
	if !ok {
		return false
	}
	graceDuration, ok := parseMillisecondsToken(line, &n, "graceDuration")
	if !ok {
		return false
	}
	if !expectEof(line, n) {
		return false
	}

	item, err := cache.GetDeAsyncItem(key, graceDuration)
	if err == ybc.ErrWouldBlock {
		return writeStr(c.Writer, strWouldBlockCrLf)
	}
	if err == ybc.ErrCacheMiss {
		return writeStr(c.Writer, strEndCrLf)
	}
	if err != nil {
		log.Fatalf("Unexpected error returned: [%s]", err)
	}
	// do not use defer item.Close() for performance reasons

	isModified, ok := checkAndUpdateCasid(item, &casid)
	if !ok {
		item.Close()
		return false
	}
	if !isModified {
		item.Close()
		return writeStr(c.Writer, strNotModifiedCrLf)
	}

	ok = writeGetResponseWithEof(c.Writer, key, item, scratchBuf)
	item.Close()
	return ok
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:45,代码来源:server.go


注:本文中的github.com/valyala/ybc/bindings/go/ybc.Cacher.GetDeAsyncItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。