本文整理汇总了Golang中github.com/valyala/ybc/bindings/go/ybc.Cacher类的典型用法代码示例。如果您正苦于以下问题:Golang Cacher类的具体用法?Golang Cacher怎么用?Golang Cacher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cacher类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: processDeleteCmd
func processDeleteCmd(c *bufio.ReadWriter, cache ybc.Cacher, line []byte, scratchBuf *[]byte) bool {
n := -1
key := nextToken(line, &n, "key")
if key == nil {
return false
}
noreply := false
if n < len(line) {
if !expectNoreply(line, &n) {
return false
}
noreply = true
}
if !expectEof(line, n) {
return false
}
ok := cache.Delete(key)
if noreply {
return true
}
response := strDeleted
if !ok {
response = strNotFound
}
return writeStr(c.Writer, response) && writeCrLf(c.Writer)
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:30,代码来源:server.go
示例4: cGetFromCache
func cGetFromCache(cache ybc.Cacher, key []byte, etag *uint64) (item *ybc.Item, err error) {
item, err = cache.GetItem(key)
if err == ybc.ErrCacheMiss {
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
示例5: getCasidForCachedItem
func getCasidForCachedItem(cache ybc.Cacher, key []byte) (casid uint64, cacheMiss, ok bool) {
item, err := cache.GetItem(key)
if err != nil {
if err == ybc.ErrCacheMiss {
cacheMiss = true
return
}
log.Fatalf("Unexpected error returned from Cache.GetItem() for key=[%s]: [%s]", key, err)
}
// do not use defer item.Close() for performance reasons
var buf [casidSize]byte
n, err := item.Read(buf[:])
item.Close()
if err != nil {
log.Printf("Error when reading casid for the item: [%s]", err)
return
}
if n != len(buf) {
log.Printf("Unexpected result returned from ybc.Item.Read(): %d. Expected %d", n, len(buf))
return
}
casid = binary.LittleEndian.Uint64(buf[:])
ok = true
return
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:26,代码来源:server.go
示例6: setToCache
func setToCache(cache ybc.Cacher, key []byte, flags uint32, expiration time.Duration, size int) *ybc.SetTxn {
size += binary.Size(&flags)
txn, err := cache.NewSetTxn(key, size, expiration)
if err != nil {
log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
return nil
}
binaryWrite(txn, &flags, "flags")
return txn
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:10,代码来源:server.go
示例7: cachedItemExists
func cachedItemExists(cache ybc.Cacher, key []byte) bool {
item, err := cache.GetItem(key)
if err == ybc.ErrCacheMiss {
return false
}
if err != nil {
log.Fatalf("Unexpected error returned from Cacher.GetItem(): [%s]", err)
}
item.Close()
return true
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:11,代码来源:server.go
示例8: getItemAndWriteResponse
func getItemAndWriteResponse(w *bufio.Writer, cache ybc.Cacher, key []byte, cas bool, scratchBuf *[]byte) bool {
item, err := cache.GetItem(key)
if err != nil {
if err == ybc.ErrCacheMiss {
return true
}
log.Fatalf("Unexpected error returned by cache.GetItem(key=[%s]): [%s]", key, err)
}
defer item.Close()
return writeGetResponse(w, key, item, cas, scratchBuf)
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:12,代码来源:server.go
示例9: cSetToCache
func cSetToCache(cache ybc.Cacher, key []byte, size int, flags uint32, expiration time.Duration, etag uint64, validateTtl uint32) *ybc.SetTxn {
size += binary.Size(&etag) + binary.Size(&validateTtl) + binary.Size(&flags)
txn, err := cache.NewSetTxn(key, size, expiration)
if err != nil {
log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
return nil
}
binaryWrite(txn, &etag, "etag")
binaryWrite(txn, &validateTtl, "validateTtl")
binaryWrite(txn, &flags, "flags")
return txn
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:12,代码来源:server.go
示例10: getItemAndWriteResponse
func getItemAndWriteResponse(w *bufio.Writer, cache ybc.Cacher, key []byte, shouldWriteCasid bool, scratchBuf *[]byte) bool {
item, err := cache.GetItem(key)
if err != nil {
if err == ybc.ErrCacheMiss {
return true
}
log.Fatalf("Unexpected error returned by cache.GetItem(key=[%s]): [%s]", key, err)
}
// do not use defer item.Close() for performance reasons
ok := writeGetResponse(w, key, item, shouldWriteCasid, scratchBuf)
item.Close()
return ok
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:14,代码来源:server.go
示例11: revalidateAndSetItemValueInternal
func revalidateAndSetItemValueInternal(client Ccacher, cache ybc.Cacher, it *ybc.Item, item *Item, casid uint64, flags, validateTtl uint32, getFunc func() error) error {
if err := getFunc(); err != nil {
if err == ErrNotModified {
if validateTtl > 0 {
updateLocalItem(cache, it, item.Key, casid, flags, validateTtl)
}
return setItemValue(it, item)
}
if err == ErrCacheMiss {
cache.Delete(item.Key)
}
return err
}
return cacheItem(cache, item)
}
开发者ID:kangkot,项目名称:ybc,代码行数:15,代码来源:caching_client.go
示例12: processFlushAllCmd
func processFlushAllCmd(c *bufio.ReadWriter, cache ybc.Cacher, line []byte, flushAllTimer **time.Timer) bool {
expiration, noreply, ok := parseFlushAllCmd(line)
if !ok {
return false
}
(*flushAllTimer).Stop()
if expiration <= 0 {
cache.Clear()
} else {
*flushAllTimer = time.AfterFunc(expiration, cacheClearFunc(cache))
}
if noreply {
return true
}
return writeStr(c.Writer, strOkCrLf)
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:16,代码来源:server.go
示例13: writeItemMetadata
func writeItemMetadata(cache ybc.Cacher, key []byte, size int, ttl time.Duration, etag uint64, validateTtl uint32, flags uint32) *ybc.SetTxn {
validateExpiration64 := uint64(time.Now().Add(time.Duration(validateTtl) * time.Millisecond).UnixNano())
size += binary.Size(&etag) + binary.Size(&validateTtl) + binary.Size(flags) + binary.Size(&validateExpiration64)
txn, err := cache.NewSetTxn(key, size, ttl)
if err != nil {
log.Printf("Unexpected error in Cache.NewSetTxn(size=%d): [%s]", size, err)
return nil
}
binaryWrite(txn, &etag, "etag")
binaryWrite(txn, &validateTtl, "validateTtl")
binaryWrite(txn, &flags, "flags")
binaryWrite(txn, &validateExpiration64, "validateExpiration")
return txn
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:17,代码来源:caching_client.go
示例14: 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
示例15: processDeleteCmd
func processDeleteCmd(c *bufio.ReadWriter, cache ybc.Cacher, line []byte, scratchBuf *[]byte) bool {
n := -1
key := nextToken(line, &n, "key")
if key == nil {
return false
}
noreply := false
if n < len(line) {
s := nextToken(line, &n, "noreply_or_exptime")
if s == nil {
return false
}
if !bytes.Equal(s, strNoreply) {
if _, ok := parseUint32(s); !ok {
return false
}
if n < len(line) {
if !expectNoreply(line, &n) {
return false
}
noreply = true
}
} else {
noreply = true
}
}
if !expectEof(line, n) {
return false
}
ok := cache.Delete(key)
if noreply {
return true
}
response := strDeletedCrLf
if !ok {
response = strNotFoundCrLf
}
return writeStr(c.Writer, response)
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:43,代码来源:server.go
示例16: startSetTxn
func startSetTxn(cache ybc.Cacher, key []byte, flags uint32, expiration time.Duration, size int) *ybc.SetTxn {
casid := getCasid()
size += casidSize + flagsSize
txn, err := cache.NewSetTxn(key, size, expiration)
if err != nil {
log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
return nil
}
var buf [casidSize + flagsSize]byte
binary.LittleEndian.PutUint64(buf[:casidSize], casid)
binary.LittleEndian.PutUint32(buf[casidSize:], flags)
n, err := txn.Write(buf[:])
if err != nil {
log.Fatalf("Error in SetTxn.Write(): [%s]", err)
}
if n != len(buf) {
log.Fatalf("Unexpected result returned from SetTxn.Write(): %d. Expected %d", n, len(buf))
}
return txn
}
开发者ID:rjmcguire,项目名称:ybc,代码行数:21,代码来源:server.go
示例17: revalidateAndSetItemValueInternal
func revalidateAndSetItemValueInternal(client Ccacher, cache ybc.Cacher, it *ybc.Item, item *Item, etag uint64, validateTtl uint32, getFunc func(*Citem) error) error {
citem := Citem{
Item: Item{
Key: item.Key,
},
Etag: etag,
}
if err := getFunc(&citem); err != nil {
if err == ErrNotModified {
if validateTtl > 0 {
updateLocalItem(cache, it, item, etag, validateTtl)
}
return setItemValue(it, item)
}
if err == ErrCacheMiss {
cache.Delete(item.Key)
}
return err
}
cacheCitem(cache, &citem)
item.Value = citem.Value
return nil
}
开发者ID:inthecloud247,项目名称:ybc,代码行数:23,代码来源:caching_client.go
示例18: writeItemMetadata
func writeItemMetadata(cache ybc.Cacher, key []byte, size int, casid uint64, flags, validateTtl uint32) *ybc.SetTxn {
validateExpiration64 := uint64(time.Now().Add(time.Duration(validateTtl) * time.Millisecond).UnixNano())
size += metadataSize
txn, err := cache.NewSetTxn(key, size, ybc.MaxTtl)
if err != nil {
log.Printf("Unexpected error in Cache.NewSetTxn(size=%d): [%s]", size, err)
return nil
}
var buf [metadataSize]byte
binary.LittleEndian.PutUint64(buf[:casidSize], casid)
binary.LittleEndian.PutUint32(buf[casidSize:], flags)
binary.LittleEndian.PutUint32(buf[casidSize+flagsSize:], validateTtl)
binary.LittleEndian.PutUint64(buf[casidSize+flagsSize+validateTtlSize:], validateExpiration64)
n, err := txn.Write(buf[:])
if err != nil {
log.Fatalf("Error in SetTxn.Write(): [%s]", err)
}
if n != len(buf) {
log.Fatalf("Unexpected result returned from SetTxn.Write(): %d. Expected %d", n, len(buf))
}
return txn
}
开发者ID:kangkot,项目名称:ybc,代码行数:24,代码来源:caching_client.go
示例19: main
func main() {
iniflags.Parse()
runtime.GOMAXPROCS(*goMaxProcs)
syncInterval_ := *syncInterval
if syncInterval_ <= 0 {
syncInterval_ = ybc.ConfigDisableSync
}
config := ybc.Config{
MaxItemsCount: ybc.SizeT(*maxItemsCount),
DataFileSize: ybc.SizeT(*cacheSize) * ybc.SizeT(1024*1024),
HotItemsCount: ybc.SizeT(*hotItemsCount),
HotDataSize: ybc.SizeT(*hotDataSize),
DeHashtableSize: *deHashtableSize,
SyncInterval: syncInterval_,
}
var cache ybc.Cacher
var err error
cacheFilesPath_ := strings.Split(*cacheFilesPath, ",")
cacheFilesCount := len(cacheFilesPath_)
log.Printf("Opening data files. This can take a while for the first time if files are big\n")
if cacheFilesCount < 2 {
if cacheFilesPath_[0] != "" {
config.DataFile = cacheFilesPath_[0] + ".go-memcached.data"
config.IndexFile = cacheFilesPath_[0] + ".go-memcached.index"
}
cache, err = config.OpenCache(true)
if err != nil {
log.Fatalf("Cannot open cache: [%s]", err)
}
} else if cacheFilesCount > 1 {
config.MaxItemsCount /= ybc.SizeT(cacheFilesCount)
config.DataFileSize /= ybc.SizeT(cacheFilesCount)
var configs ybc.ClusterConfig
configs = make([]*ybc.Config, cacheFilesCount)
for i := 0; i < cacheFilesCount; i++ {
cfg := config
cfg.DataFile = cacheFilesPath_[i] + ".go-memcached.data"
cfg.IndexFile = cacheFilesPath_[i] + ".go-memcached.index"
configs[i] = &cfg
}
cache, err = configs.OpenCluster(true)
if err != nil {
log.Fatalf("Cannot open cache cluster: [%s]", err)
}
}
defer cache.Close()
log.Printf("Data files have been opened\n")
s := memcache.Server{
Cache: cache,
ListenAddr: *listenAddr,
ReadBufferSize: *readBufferSize,
WriteBufferSize: *writeBufferSize,
OSReadBufferSize: *osReadBufferSize,
OSWriteBufferSize: *osWriteBufferSize,
}
log.Printf("Starting the server")
if err := s.Serve(); err != nil {
log.Fatalf("Cannot serve traffic: [%s]", err)
}
}
开发者ID:kangkot,项目名称:ybc,代码行数:65,代码来源:main.go
注:本文中的github.com/valyala/ybc/bindings/go/ybc.Cacher类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论