func (this *Cache) Delete(key string) { this.client.Delete(key) if conf.IsDev() { log.Println("cache delete:", key) } }
func init() { dataSource := conf.Config.Datasource maxIdleConns := conf.Config.MaxIdleConns maxOpenConns := conf.Config.MaxOpenConns log.Println("mysql datasource:", dataSource, ", maxIdleConns", maxIdleConns, ", maxOpenConns", maxOpenConns) db, err := sql.Open("mysql", dataSource) utils.HandleError(err) db.SetMaxIdleConns(maxIdleConns) db.SetMaxOpenConns(maxOpenConns) DbMap = &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}} // Trace query log if conf.IsDev() { DbMap.TraceOn("", log.New(os.Stdout, "", log.Lmicroseconds)) } // Define table metadata new(UserManager).AddTable() new(ChatroomManager).AddTable() utils.HandleError(DbMap.CreateTablesIfNotExists()) }
func (this *Cache) Put(key string, value []byte) { item := memcache.Item{Key: key, Value: value} this.client.Set(&item) if conf.IsDev() { log.Println("cache put:", key) } }
func (this *Cache) Increment(key string, delta uint64) uint64 { newValue, err := this.client.Increment(key, delta) utils.HandleError(err) if conf.IsDev() { log.Println("cache increment:", key, delta) } return newValue }
func (this *Cache) Get(key string) []byte { item, err := this.client.Get(key) if conf.IsDev() { utils.HandleError(err) } if item == nil { if conf.IsDev() { log.Println("cache not hit:", key) } return nil } if conf.IsDev() { log.Println("cache hit:", key) } return item.Value }
func initGorelic() { if !conf.IsDev() { return } agent = gorelic.NewAgent() agent.NewrelicName = "go-gamereviews" agent.Verbose = true agent.NewrelicLicense = conf.Config.NewrelicLicense agent.CollectHTTPStat = true agent.HTTPTimer = metrics.NewTimer() agent.Run() }