// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.

/*
  Package timemachine is a generated cache proxy package.
  It is generated from:
  type _cache interface {
		// cache
		Timemachine(c context.Context, mid int64) (*timemachine.Item, error)
	}
*/

package timemachine

import (
	"context"

	"go-common/app/interface/main/activity/model/timemachine"
	"go-common/library/stat/prom"
)

var _ _cache

// Timemachine get data from cache if miss will call source method, then add to cache.
func (d *Dao) Timemachine(c context.Context, id int64) (res *timemachine.Item, err error) {
	addCache := true
	res, err = d.CacheTimemachine(c, id)
	if err != nil {
		addCache = false
		err = nil
	}
	if res != nil {
		prom.CacheHit.Incr("Timemachine")
		return
	}
	prom.CacheMiss.Incr("Timemachine")
	res, err = d.RawTimemachine(c, id)
	if err != nil {
		return
	}
	miss := res
	if !addCache {
		return
	}
	d.cache.Do(c, func(c context.Context) {
		d.AddCacheTimemachine(c, id, miss)
	})
	return
}
