From c7e0d3a499941a4cbd7814e30308c8f3c6e45543 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 21 Mar 2014 21:06:47 +0800 Subject: [PATCH] add cache --- conf/app.ini | 4 ++++ modules/base/conf.go | 16 ++++++++++++++++ modules/middleware/context.go | 3 +++ 3 files changed, 23 insertions(+) diff --git a/conf/app.ini b/conf/app.ini index 985903a8e5..71fe81e834 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -60,6 +60,10 @@ FROM = USER = PASSWD = +[cache] +ADAPTER = memory +CONFIG = + [log] ; Either "console", "file", "conn" or "smtp", default is "console" MODE = console diff --git a/modules/base/conf.go b/modules/base/conf.go index bf054ec3c5..3962972cda 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -15,6 +15,8 @@ import ( "github.com/Unknwon/com" "github.com/Unknwon/goconfig" + "github.com/gogits/cache" + "github.com/gogits/gogs/modules/log" ) @@ -37,6 +39,10 @@ var ( Cfg *goconfig.ConfigFile MailService *Mailer + + Cache cache.Cache + CacheAdapter string + CacheConfig string ) var Service struct { @@ -182,6 +188,16 @@ func NewConfigContext() { SecretKey = Cfg.MustValue("security", "SECRET_KEY") RunUser = Cfg.MustValue("", "RUN_USER") + CacheAdapter = Cfg.MustValue("cache", "ADAPTER") + CacheConfig = Cfg.MustValue("cache", "CONFIG") + + Cache, err = cache.NewCache(CacheAdapter, CacheConfig) + if err != nil { + fmt.Printf("Init cache system failed, adapter: %s, config: %s, %v\n", + CacheAdapter, CacheConfig, err) + os.Exit(2) + } + // Determine and create root git reposiroty path. RepoRootPath = Cfg.MustValue("repository", "ROOT") if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil { diff --git a/modules/middleware/context.go b/modules/middleware/context.go index cb3cbabca6..da051918b1 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -12,6 +12,8 @@ import ( "github.com/codegangsta/martini" "github.com/martini-contrib/sessions" + "github.com/gogits/cache" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/log" @@ -25,6 +27,7 @@ type Context struct { Req *http.Request Res http.ResponseWriter Session sessions.Session + Cache cache.Cache User *models.User IsSigned bool