示例#1
0
func init() {
	Logger.Info("init cache ...")
	Cache = cache.NewRedisCache(config.AuthPageConfig.RedisHost, config.AuthPageConfig.RedisPassword, constant.LOGIN_EXPIRED_TIME)
	if err := Cache.Set("_test_is_valid_x_", "x", time.Second); err != nil {
		Logger.Error("error redis status,%v, will use memcached", err)
		Cache = cache.NewMemcachedStore(config.AuthPageConfig.MemcachedHosts, constant.LOGIN_EXPIRED_TIME)
		if err = Cache.Set("_test_is_valid_x_", "x", time.Second); err != nil {
			Logger.Error("error redis status,%v, will use memry cache", err)
			Cache = cache.NewInMemoryStore(constant.LOGIN_EXPIRED_TIME)
		}
	}

	Logger.Info("cache inited")
}
示例#2
0
func Cache() gin.HandlerFunc {
	var store gin_cache.CacheStore

	switch conf.CACHE_STORE {
	case conf.MEMCACHED:
		store = gin_cache.NewMemcachedStore([]string{conf.MEMCACHED_SERVER}, time.Hour)
	default:
		store = gin_cache.NewInMemoryStore(time.Hour)
	}

	return func(c *gin.Context) {
		c.Set(DefaultKey, store)
		c.Next()
	}
}
示例#3
0
文件: cache.go 项目: sdvdxl/wine
func init() {
	log.Logger.Info("init cache ...")
	//	Cache = cache.NewRedisCache("redis-31pzn.q1.tenxcloud.net:48181", "Isdvdxl8", constant.LOGIN_EXPIRED_TIME)
	Cache = cache.NewRedisCache("54.223.168.107:61993", "Isdvdxl8", constant.LOGIN_EXPIRED_TIME)
	if err := Cache.Set("_test_is_valid_x_", "x", time.Second); err != nil {
		log.Logger.Error("error redis status,%v, will use memcached", err)
		Cache = cache.NewMemcachedStore([]string{}, constant.LOGIN_EXPIRED_TIME)
		if err = Cache.Set("_test_is_valid_x_", "x", time.Second); err != nil {
			log.Logger.Error("error redis status,%v, will use memry cache", err)
			Cache = cache.NewInMemoryStore(constant.LOGIN_EXPIRED_TIME)
		}
	}

	log.Logger.Info("cache inited")
}