]> source.dussan.org Git - gitea.git/commitdiff
add cache
authorslene <vslene@gmail.com>
Fri, 21 Mar 2014 13:06:47 +0000 (21:06 +0800)
committerslene <vslene@gmail.com>
Fri, 21 Mar 2014 13:06:47 +0000 (21:06 +0800)
conf/app.ini
modules/base/conf.go
modules/middleware/context.go

index 985903a8e5271afb38325ddd3e3912023779fec0..71fe81e83499302155aa6559bf8fe04bd2016833 100644 (file)
@@ -60,6 +60,10 @@ FROM =
 USER = 
 PASSWD = 
 
+[cache]
+ADAPTER = memory
+CONFIG = 
+
 [log]
 ; Either "console", "file", "conn" or "smtp", default is "console"
 MODE = console
index bf054ec3c57697a61dba69c6fb68adfc96ed34ad..3962972cda0351a0788a4827deba3c9d9abaa27b 100644 (file)
@@ -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 {
index cb3cbabca62872044a40f870c2e0d6de1edcb968..da051918b1161be2fed03ada981f3fb8afdc4151 100644 (file)
@@ -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