Exemple #1
0
func (this *FunServantImpl) LcGet(ctx *rpc.Context, key string) (r []byte,
	miss *rpc.TCacheMissed, ex error) {
	const IDENT = "lc.get"

	svtStats.inc(IDENT)

	profiler, err := this.getSession(ctx).startProfiler()
	if err != nil {
		ex = err
		return
	}

	result, ok := this.lc.Get(key)
	if !ok {
		miss = rpc.NewTCacheMissed()
		miss.Message = thrift.StringPtr("lcache missed: " + key) // optional
	} else {
		r = result.([]byte)
	}

	profiler.do(IDENT, ctx,
		"{key^%s} {miss^%v r^%s}", key, miss, r)

	return
}
Exemple #2
0
func (this *FunServantImpl) LcGet(ctx *rpc.Context, key string) (r []byte,
	miss *rpc.TCacheMissed, intError error) {
	result, ok := this.lc.Get(key)
	if !ok {
		miss = rpc.NewTCacheMissed()
		miss.Message = thrift.StringPtr("lcache missed: " + key) // optional
	} else {
		r = result.([]byte)
	}

	return
}
Exemple #3
0
func (this *FunServantImpl) McGet(ctx *rpc.Context, pool string,
	key string) (r *rpc.TMemcacheData,
	miss *rpc.TCacheMissed, ex error) {
	const IDENT = "mc.get"

	if this.mc == nil {
		ex = ErrServantNotStarted
		return
	}

	svtStats.inc(IDENT)

	profiler, err := this.getSession(ctx).startProfiler()
	if err != nil {
		ex = err
		return
	}

	it, err := this.mc.Get(pool, key)
	if err == nil {
		// cache hit
		r = rpc.NewTMemcacheData()
		r.Data = it.Value
		r.Flags = int32(it.Flags)
	} else if err == memcache.ErrCacheMiss {
		// cache miss
		miss = rpc.NewTCacheMissed()
		miss.Message = thrift.StringPtr(err.Error()) // optional
	} else {
		ex = err
		log.Error("Q=%s %s {key^%s}: %v", IDENT, ctx.String(), key, err)
	}

	profiler.do(IDENT, ctx,
		"{key^%s} {miss^%v val^%s}",
		key,
		miss,
		r)

	return
}
Exemple #4
0
func (this *FunServantImpl) McGet(ctx *rpc.Context, key string) (r []byte,
	miss *rpc.TCacheMissed, intError error) {
	profiler := this.profiler()

	it, err := this.mc.Get(key)
	if err == nil {
		// cache hit
		r = it.Value
	} else if err == memcache.ErrCacheMiss {
		// cache miss
		miss = rpc.NewTCacheMissed()
		miss.Message = thrift.StringPtr(err.Error()) // optional
	} else {
		intError = err
		log.Error(err)
	}

	profiler.do("mc.get", ctx,
		"{key^%s} {%s}",
		key,
		this.truncatedBytes(r))

	return
}