• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang cache.Cacher函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/go-macaron/cache.Cacher函数的典型用法代码示例。如果您正苦于以下问题:Golang Cacher函数的具体用法?Golang Cacher怎么用?Golang Cacher使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Cacher函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: initCaptch

func initCaptch(m *macaron.Macaron) {
	m.Use(cache.Cacher())

	width := 240
	height := 80
	expiration := int64(600)

	cfg := macaron.Config()
	capcfg, err := cfg.GetSection("captcha")

	if err != nil {
		width = capcfg.Key("width").MustInt(width)
		height = capcfg.Key("height").MustInt(height)
		expiration = capcfg.Key("expire").MustInt64(expiration)
	}

	m.Use(captcha.Captchaer(captcha.Options{
		URLPrefix:        "/captcha/img/", // 获取验证码图片的 URL 前缀,默认为 "/captcha/"
		FieldIdName:      "captcha_id",    // 表单隐藏元素的 ID 名称,默认为 "captcha_id"
		FieldCaptchaName: "captcha",       // 用户输入验证码值的元素 ID,默认为 "captcha"
		ChallengeNums:    6,               // 验证字符的个数,默认为 6
		Width:            width,           // 验证码图片的宽度,默认为 240 像素
		Height:           height,          // 验证码图片的高度,默认为 80 像素
		Expiration:       expiration,      // 验证码过期时间,默认为 600 秒
		CachePrefix:      "captcha_",      // 用于存储验证码正确值的 Cache 键名,默认为 "captcha_"
	}))
}
开发者ID:wcreate,项目名称:wuc,代码行数:27,代码来源:init.go


示例2: main

func main() {
	m := macaron.Classic()
	m.Use(cache.Cacher())
	// m.Use(session.Sessioner())
	m.Use(session.Sessioner(session.Options{
		Provider:       "memory",
		ProviderConfig: "",
		CookieName:     "Kfx",
		CookiePath:     "/",
		Gclifetime:     3600,
		Maxlifetime:    3600,
		Secure:         false,
		CookieLifeTime: 0,
		Domain:         "/",
		IDLength:       16,
		Section:        "session",
	}))
	m.Use(csrf.Csrfer())
	m.Use(captcha.Captchaer(captcha.Options{
		// 获取验证码图片的 URL 前缀,默认为 "/captcha/"
		URLPrefix: "/captcha/",
		// 表单隐藏元素的 ID 名称,默认为 "captcha_id"
		FieldIdName: "captcha_id",
		// 用户输入验证码值的元素 ID,默认为 "captcha"
		FieldCaptchaName: "captcha",
		// 验证字符的个数,默认为 6
		ChallengeNums: 6,
		// 验证码图片的宽度,默认为 240 像素
		Width: 240,
		// 验证码图片的高度,默认为 80 像素
		Height: 80,
		// 验证码过期时间,默认为 600 秒
		Expiration: 600,
		// 用于存储验证码正确值的 Cache 键名,默认为 "captcha_"
		CachePrefix: "captcha_",
	}))
	m.Use(renders.Renderer(renders.Options{
		Directory:       "templates",
		Extensions:      []string{".html"},
		Charset:         "UTF-8",
		IndentJSON:      true,
		IndentXML:       true,
		HTMLContentType: "text/html",
	}))

	m.Get("/", index.Index)

	m.NotFound(func(r renders.Render) {
		r.HTML(200, "404.html", map[string]interface{}{"Title": "Home"})
	})
	m.Run()
}
开发者ID:myafeier,项目名称:GoCMS,代码行数:52,代码来源:main.go


示例3: newMacaron

func newMacaron() *macaron.Macaron {
	m := macaron.New()
	m.Use(macaron.Renderer(macaron.RenderOptions{Layout: "layout",
		Funcs: []template.FuncMap{{
			"markdown": base.Markdown,
			"raw":      func(s string) template.HTML { return template.HTML(s) },
			"momentDiff": func(t time.Time) string {
				return since.Since(t)
			},
		}}}))
	/*	m.Use(func(c *macaron.Context) {
		if strings.HasSuffix(c.Req.URL.Path, ".json") {
			color.Green("JSON")

			c.Req.Request.URL

			c.Req.URL.Path = strings.TrimSuffix(c.Req.URL.Path, ".json")
			c.Req.URL.RawPath = strings.TrimSuffix(c.Req.URL.RawPath, ".json")
			c.Req.RequestURI = c.Req.URL.RequestURI()

			c.Data["json"] = true
		}
		c.Next()
	})*/
	m.Use(cache.Cacher())
	m.Use(session.Sessioner())
	m.Use(csrf.Csrfer())
	m.Use(macaron.Static("static"))
	m.Use(macaron.Static("data/uploads"))
	m.Use(macaron.Static("data/public", macaron.StaticOptions{Prefix: "public"}))

	m.Use(i18n.I18n(i18n.Options{
		Langs: []string{"en-US", "ru-RU"},
		Names: []string{"English", "Русский"},
	}))

	m.Use(middleware.Contexter())

	return m
}
开发者ID:zhuharev,项目名称:smoljanin.ru,代码行数:40,代码来源:web.go


示例4: main

func main() {
	log.Debug("Starting server...")

	m := macaron.New()
	m.Use(macaron.Logger())
	m.Use(macaron.Recovery())
	m.Use(cache.Cacher())
	m.Use(session.Sessioner(session.Options{CookieName: "s"}))
	m.Use(captcha.Captchaer(captcha.Options{Width: 120, Height: 40}))
	m.Use(macaron.Static("static", macaron.StaticOptions{Prefix: "/static"}))
	m.Use(pongo2.Pongoer())
	//m.Use(i18n.I18n(i18n.Options{
	//	Langs: []string{"en-US", "zh-CN"},
	//	Names: []string{"English", "简体中文"},
	//}))
	m.Use(spider.SpiderFunc())
	m.Use(token.Tokener())

	boot.BootStrap()
	router.Route(m)

	m.Run(boot.WebListenIP, boot.WebPort)
}
开发者ID:xtfly,项目名称:goman,代码行数:23,代码来源:app.go


示例5: newMacaron

// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
	m := macaron.New()
	if !setting.DisableRouterLog {
		m.Use(macaron.Logger())
	}
	m.Use(macaron.Recovery())
	if setting.EnableGzip {
		m.Use(gzip.Gziper())
	}
	if setting.Protocol == setting.FCGI {
		m.SetURLPrefix(setting.AppSubUrl)
	}
	m.Use(macaron.Static(
		path.Join(setting.StaticRootPath, "public"),
		macaron.StaticOptions{
			SkipLogging: setting.DisableRouterLog,
		},
	))
	m.Use(macaron.Static(
		setting.AvatarUploadPath,
		macaron.StaticOptions{
			Prefix:      "avatars",
			SkipLogging: setting.DisableRouterLog,
		},
	))
	m.Use(macaron.Renderer(macaron.RenderOptions{
		Directory:  path.Join(setting.StaticRootPath, "templates"),
		Funcs:      []gotmpl.FuncMap{template.Funcs},
		IndentJSON: macaron.Env != macaron.PROD,
	}))

	localeNames, err := bindata.AssetDir("conf/locale")
	if err != nil {
		log.Fatal(4, "Fail to list locale files: %v", err)
	}
	localFiles := make(map[string][]byte)
	for _, name := range localeNames {
		localFiles[name] = bindata.MustAsset("conf/locale/" + name)
	}
	m.Use(i18n.I18n(i18n.Options{
		SubURL:          setting.AppSubUrl,
		Files:           localFiles,
		CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
		Langs:           setting.Langs,
		Names:           setting.Names,
		DefaultLang:     "en-US",
		Redirect:        true,
	}))
	m.Use(cache.Cacher(cache.Options{
		Adapter:       setting.CacheAdapter,
		AdapterConfig: setting.CacheConn,
		Interval:      setting.CacheInternal,
	}))
	m.Use(captcha.Captchaer(captcha.Options{
		SubURL: setting.AppSubUrl,
	}))
	m.Use(session.Sessioner(setting.SessionConfig))
	m.Use(csrf.Csrfer(csrf.Options{
		Secret:     setting.SecretKey,
		SetCookie:  true,
		Header:     "X-Csrf-Token",
		CookiePath: setting.AppSubUrl,
	}))
	m.Use(toolbox.Toolboxer(m, toolbox.Options{
		HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
			&toolbox.HealthCheckFuncDesc{
				Desc: "Database connection",
				Func: models.Ping,
			},
		},
	}))
	m.Use(middleware.Contexter())
	return m
}
开发者ID:abhijitmamarde,项目名称:gogs,代码行数:75,代码来源:web.go


示例6: newMacaron

func newMacaron() *macaron.Macaron {
	m := macaron.New()

	// DISABLE_ROUTER_LOG: 激活该选项来禁止打印路由日志
	// 判断是否禁用,如果禁用则引入macaron日志
	if !setting.DisableRouterLog {
		m.Use(macaron.Logger())
	}
	// 引入macaron恢复机制
	m.Use(macaron.Recovery())

	if setting.Protocol == setting.FCGI {
		m.SetURLPrefix(setting.AppSubUrl)
	}

	// 设定静态资源路径
	m.Use(macaron.Static(
		path.Join(setting.StaticRootPath, "public"),
		macaron.StaticOptions{
			SkipLogging: setting.DisableRouterLog,
		},
	))
	m.Use(macaron.Static(
		setting.AvatarUploadPath,
		macaron.StaticOptions{
			Prefix:      "avatars",
			SkipLogging: setting.DisableRouterLog,
		},
	))

	// 设置渲染模板
	m.Use(macaron.Renderer(macaron.RenderOptions{
		Directory:         path.Join(setting.StaticRootPath, "templates"),
		AppendDirectories: []string{path.Join(setting.CustomPath, "templates")},
		Funcs:             template.NewFuncMap(),
		IndentJSON:        macaron.Env != macaron.PROD,
	}))

	// 指定国际化目录
	localeNames, err := bindata.AssetDir("conf/locale")
	if err != nil {
		log.Fatal(4, "Fail to list locale files: %v", err)
	}
	localFiles := make(map[string][]byte)
	for _, name := range localeNames {
		localFiles[name] = bindata.MustAsset("conf/locale/" + name)
	}

	m.Use(i18n.I18n(i18n.Options{
		SubURL:          setting.AppSubUrl,
		Files:           localFiles,
		CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
		Langs:           setting.Langs,
		Names:           setting.Names,
		DefaultLang:     "en-US",
		Redirect:        true,
	}))
	m.Use(cache.Cacher(cache.Options{
		Adapter:       setting.CacheAdapter,
		AdapterConfig: setting.CacheConn,
		Interval:      setting.CacheInternal,
	}))
	m.Use(captcha.Captchaer(captcha.Options{
		SubURL: setting.AppSubUrl,
	}))
	m.Use(session.Sessioner(setting.SessionConfig))
	m.Use(csrf.Csrfer(csrf.Options{
		Secret:     setting.SecretKey,
		Cookie:     setting.CSRFCookieName,
		SetCookie:  true,
		Header:     "X-Csrf-Token",
		CookiePath: setting.AppSubUrl,
	}))
	m.Use(toolbox.Toolboxer(m, toolbox.Options{
		HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
			&toolbox.HealthCheckFuncDesc{
				Desc: "Database connection",
				Func: models.Ping,
			},
		},
	}))
	//m.Use(context.Contexter())
	return m
}
开发者ID:kuuyee,项目名称:gogs-learn,代码行数:84,代码来源:web.go


示例7: Test_LedisCacher

func Test_LedisCacher(t *testing.T) {
	Convey("Test nodb cache adapter", t, func() {
		opt := cache.Options{
			Adapter:       "nodb",
			AdapterConfig: "./tmp.db",
		}

		Convey("Basic operations", func() {
			m := macaron.New()
			m.Use(cache.Cacher(opt))

			m.Get("/", func(c cache.Cache) {
				So(c.Put("uname", "unknwon", 1), ShouldBeNil)
				So(c.Put("uname2", "unknwon2", 1), ShouldBeNil)
				So(c.IsExist("uname"), ShouldBeTrue)

				So(c.Get("404"), ShouldBeNil)
				So(c.Get("uname").(string), ShouldEqual, "unknwon")

				time.Sleep(2 * time.Second)
				So(c.Get("uname"), ShouldBeNil)
				time.Sleep(1 * time.Second)
				So(c.Get("uname2"), ShouldBeNil)

				So(c.Put("uname", "unknwon", 0), ShouldBeNil)
				So(c.Delete("uname"), ShouldBeNil)
				So(c.Get("uname"), ShouldBeNil)

				So(c.Put("uname", "unknwon", 0), ShouldBeNil)
				So(c.Flush(), ShouldBeNil)
				So(c.Get("uname"), ShouldBeNil)
			})

			resp := httptest.NewRecorder()
			req, err := http.NewRequest("GET", "/", nil)
			So(err, ShouldBeNil)
			m.ServeHTTP(resp, req)

			m.Get("/id", func(c cache.Cache) {
				So(c.Incr("404"), ShouldNotBeNil)
				So(c.Decr("404"), ShouldNotBeNil)

				So(c.Put("int", 0, 0), ShouldBeNil)
				So(c.Put("int64", int64(0), 0), ShouldBeNil)
				So(c.Put("string", "hi", 0), ShouldBeNil)

				So(c.Incr("int"), ShouldBeNil)
				So(c.Incr("int64"), ShouldBeNil)

				So(c.Decr("int"), ShouldBeNil)
				So(c.Decr("int64"), ShouldBeNil)

				So(c.Incr("string"), ShouldNotBeNil)
				So(c.Decr("string"), ShouldNotBeNil)

				So(com.StrTo(c.Get("int").(string)).MustInt(), ShouldEqual, 0)
				So(com.StrTo(c.Get("int64").(string)).MustInt64(), ShouldEqual, 0)

				So(c.Flush(), ShouldBeNil)
			})

			resp = httptest.NewRecorder()
			req, err = http.NewRequest("GET", "/id", nil)
			So(err, ShouldBeNil)
			m.ServeHTTP(resp, req)
		})
	})
}
开发者ID:kenno,项目名称:cache,代码行数:68,代码来源:nodb_test.go


示例8: Test_MysqlCacher

func Test_MysqlCacher(t *testing.T) {
	Convey("Test mysql cache adapter", t, func() {
		opt := cache.Options{
			Adapter:       "mysql",
			AdapterConfig: "root:@tcp(localhost:3306)/macaron?charset=utf8",
		}

		Convey("Basic operations", func() {
			m := macaron.New()
			m.Use(cache.Cacher(opt))

			m.Get("/", func(c cache.Cache) {
				So(c.Put("uname", "unknwon", 1), ShouldBeNil)
				So(c.Put("uname2", "unknwon2", 1), ShouldBeNil)
				So(c.IsExist("uname"), ShouldBeTrue)

				So(c.Get("404"), ShouldBeNil)
				So(c.Get("uname").(string), ShouldEqual, "unknwon")

				time.Sleep(1 * time.Second)
				So(c.Get("uname"), ShouldBeNil)
				time.Sleep(1 * time.Second)
				So(c.Get("uname2"), ShouldBeNil)

				So(c.Put("uname", "unknwon", 0), ShouldBeNil)
				So(c.Delete("uname"), ShouldBeNil)
				So(c.Get("uname"), ShouldBeNil)

				So(c.Put("uname", "unknwon", 0), ShouldBeNil)
				So(c.Flush(), ShouldBeNil)
				So(c.Get("uname"), ShouldBeNil)

				So(c.Put("struct", opt, 0), ShouldBeNil)
			})

			resp := httptest.NewRecorder()
			req, err := http.NewRequest("GET", "/", nil)
			So(err, ShouldBeNil)
			m.ServeHTTP(resp, req)
		})

		Convey("Increase and decrease operations", func() {
			m := macaron.New()
			m.Use(cache.Cacher(opt))

			m.Get("/", func(c cache.Cache) {
				// Escape GC at the momment.
				time.Sleep(1 * time.Second)

				So(c.Incr("404"), ShouldNotBeNil)
				So(c.Decr("404"), ShouldNotBeNil)

				So(c.Put("int", 0, 0), ShouldBeNil)
				So(c.Put("int32", int32(0), 0), ShouldBeNil)
				So(c.Put("int64", int64(0), 0), ShouldBeNil)
				So(c.Put("uint", uint(0), 0), ShouldBeNil)
				So(c.Put("uint32", uint32(0), 0), ShouldBeNil)
				So(c.Put("uint64", uint64(0), 0), ShouldBeNil)
				So(c.Put("string", "hi", 0), ShouldBeNil)

				So(c.Decr("uint"), ShouldNotBeNil)
				So(c.Decr("uint32"), ShouldNotBeNil)
				So(c.Decr("uint64"), ShouldNotBeNil)

				So(c.Incr("int"), ShouldBeNil)
				So(c.Incr("int32"), ShouldBeNil)
				So(c.Incr("int64"), ShouldBeNil)
				So(c.Incr("uint"), ShouldBeNil)
				So(c.Incr("uint32"), ShouldBeNil)
				So(c.Incr("uint64"), ShouldBeNil)

				So(c.Decr("int"), ShouldBeNil)
				So(c.Decr("int32"), ShouldBeNil)
				So(c.Decr("int64"), ShouldBeNil)
				So(c.Decr("uint"), ShouldBeNil)
				So(c.Decr("uint32"), ShouldBeNil)
				So(c.Decr("uint64"), ShouldBeNil)

				So(c.Incr("string"), ShouldNotBeNil)
				So(c.Decr("string"), ShouldNotBeNil)

				So(c.Get("int"), ShouldEqual, 0)
				So(c.Get("int32"), ShouldEqual, 0)
				So(c.Get("int64"), ShouldEqual, 0)
				So(c.Get("uint"), ShouldEqual, 0)
				So(c.Get("uint32"), ShouldEqual, 0)
				So(c.Get("uint64"), ShouldEqual, 0)

				So(c.Flush(), ShouldBeNil)
			})

			resp := httptest.NewRecorder()
			req, err := http.NewRequest("GET", "/", nil)
			So(err, ShouldBeNil)
			m.ServeHTTP(resp, req)
		})
	})
}
开发者ID:kenno,项目名称:cache,代码行数:98,代码来源:mysql_test.go


示例9: Test_PostgresCacher

func Test_PostgresCacher(t *testing.T) {
	Convey("Test postgres cache adapter", t, func() {
		opt := cache.Options{
			Adapter:       "postgres",
			AdapterConfig: "user=jiahuachen dbname=macaron port=5432 sslmode=disable",
		}

		Convey("Basic operations", func() {
			m := macaron.New()
			m.Use(cache.Cacher(opt))

			m.Get("/", func(c cache.Cache) {
				So(c.Put("uname", "unknwon", 1), ShouldBeNil)
				So(c.Put("uname2", "unknwon2", 1), ShouldBeNil)
				So(c.IsExist("uname"), ShouldBeTrue)

				So(c.Get("404"), ShouldBeNil)
				So(c.Get("uname").(string), ShouldEqual, "unknwon")

				time.Sleep(1 * time.Second)
				So(c.Get("uname"), ShouldBeNil)
				time.Sleep(1 * time.Second)
				So(c.Get("uname2"), ShouldBeNil)

				So(c.Put("uname", "unknwon", 0), ShouldBeNil)
				So(c.Delete("uname"), ShouldBeNil)
				So(c.Get("uname"), ShouldBeNil)

				So(c.Put("uname", "unknwon", 0), ShouldBeNil)
				So(c.Flush(), ShouldBeNil)
				So(c.Get("uname"), ShouldBeNil)

				So(c.Put("struct", opt, 0), ShouldBeNil)
			})

			resp := httptest.NewRecorder()
			req, err := http.NewRequest("GET", "/", nil)
			So(err, ShouldBeNil)
			m.ServeHTTP(resp, req)
		})

		Convey("Increase and decrease operations", func() {
			m := macaron.New()
			m.Use(cache.Cacher(opt))

			m.Get("/", func(c cache.Cache) {
				// Escape GC at the momment.
				time.Sleep(1 * time.Second)

				So(c.Incr("404"), ShouldNotBeNil)
				So(c.Decr("404"), ShouldNotBeNil)

				So(c.Put("int", 0, 0), ShouldBeNil)
				So(c.Put("int32", int32(0), 0), ShouldBeNil)
				So(c.Put("int64", int64(0), 0), ShouldBeNil)
				So(c.Put("uint", uint(0), 0), ShouldBeNil)
				So(c.Put("uint32", uint32(0), 0), ShouldBeNil)
				So(c.Put("uint64", uint64(0), 0), ShouldBeNil)
				So(c.Put("string", "hi", 0), ShouldBeNil)

				So(c.Decr("uint"), ShouldNotBeNil)
				So(c.Decr("uint32"), ShouldNotBeNil)
				So(c.Decr("uint64"), ShouldNotBeNil)

				So(c.Incr("int"), ShouldBeNil)
				So(c.Incr("int32"), ShouldBeNil)
				So(c.Incr("int64"), ShouldBeNil)
				So(c.Incr("uint"), ShouldBeNil)
				So(c.Incr("uint32"), ShouldBeNil)
				So(c.Incr("uint64"), ShouldBeNil)

				So(c.Decr("int"), ShouldBeNil)
				So(c.Decr("int32"), ShouldBeNil)
				So(c.Decr("int64"), ShouldBeNil)
				So(c.Decr("uint"), ShouldBeNil)
				So(c.Decr("uint32"), ShouldBeNil)
				So(c.Decr("uint64"), ShouldBeNil)

				So(c.Incr("string"), ShouldNotBeNil)
				So(c.Decr("string"), ShouldNotBeNil)

				So(c.Get("int"), ShouldEqual, 0)
				So(c.Get("int32"), ShouldEqual, 0)
				So(c.Get("int64"), ShouldEqual, 0)
				So(c.Get("uint"), ShouldEqual, 0)
				So(c.Get("uint32"), ShouldEqual, 0)
				So(c.Get("uint64"), ShouldEqual, 0)

				So(c.Flush(), ShouldBeNil)
			})

			resp := httptest.NewRecorder()
			req, err := http.NewRequest("GET", "/", nil)
			So(err, ShouldBeNil)
			m.ServeHTTP(resp, req)
		})
	})
}
开发者ID:kenno,项目名称:cache,代码行数:98,代码来源:postgres_test.go



注:本文中的github.com/go-macaron/cache.Cacher函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang captcha.Captchaer函数代码示例发布时间:2022-05-23
下一篇:
Golang binding.Errors类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap