當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。