Skip to content

Commit 6a86a47

Browse files
committed
Default use default cache configuration
1 parent 30e7727 commit 6a86a47

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ ITEM_TTL = 16h
650650
[cache.last_commit]
651651
; if the cache enabled
652652
ENABLED = true
653+
; if use the default cache, by pass all the next options
654+
USE_SEPERATE_CACHE = false
653655
; Either "memory", "redis", or "memcache", default is "memory"
654656
ADAPTER = memory
655657
; For "memory" only, GC interval in seconds, default is 60

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ relation to port exhaustion.
394394
## Cache - LastCommitCache settings (`cache.last_commit`)
395395

396396
- `ENABLED`: **true**: Enable the cache.
397+
- `USE_SEPERATE_CACHE`: **false** If use a seperate cache setting, `false` will bypass all the next options.
397398
- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`.
398399
- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only.
399400
- `HOST`: **\<empty\>**: Connection string for `redis` and `memcache`.

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ menu:
159159
## Cache - LastCommitCache settings (`cache.last_commit`)
160160

161161
- `ENABLED`: **true**: 是否启用。
162+
- `USE_SEPERATE_CACHE`: **false** 是否启用独立的Cache设置,如果为否,则以下的Cache设置无效。
162163
- `ADAPTER`: **memory**: 缓存引擎,可以为 `memory`, `redis``memcache`
163164
- `INTERVAL`: **60**: 只对内存缓存有效,GC间隔,单位秒。
164165
- `HOST`: **\<empty\>**: 针对redis和memcache有效,主机地址和端口。

modules/cache/last_commit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func NewLastCommitCache(repoPath string, gitRepo *git.Repository, ttl int64) *La
3434
}
3535
}
3636

37+
// Get get the last commit information by commit id and entry path
3738
func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) {
3839
v := c.Cache.Get(fmt.Sprintf("%s:%s:%s", c.repoPath, ref, entryPath))
3940
if vs, ok := v.(string); ok {
@@ -56,6 +57,7 @@ func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) {
5657
return nil, nil
5758
}
5859

60+
// Put put the last commit id with commit and entry path
5961
func (c LastCommitCache) Put(ref, entryPath, commitID string) error {
6062
log.Trace("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID)
6163
return c.Cache.Put(fmt.Sprintf("%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl)

modules/setting/cache.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ var (
2727

2828
LastCommit struct {
2929
Cache
30-
CommitsCount int64
30+
UseSeperateCache bool
31+
CommitsCount int64
3132
} `ini:"cache.last_commit"`
3233
}{
3334
Cache: Cache{
@@ -38,15 +39,17 @@ var (
3839
},
3940
LastCommit: struct {
4041
Cache
41-
CommitsCount int64
42+
UseSeperateCache bool
43+
CommitsCount int64
4244
}{
4345
Cache: Cache{
4446
Enabled: true,
4547
Adapter: "memory",
4648
Interval: 60,
4749
TTL: 86400 * time.Hour,
4850
},
49-
CommitsCount: 1000,
51+
UseSeperateCache: false,
52+
CommitsCount: 1000,
5053
},
5154
}
5255
)
@@ -73,16 +76,19 @@ func newCacheService() {
7376
}
7477

7578
sec = Cfg.Section("cache.last_commit")
76-
77-
CacheService.LastCommit.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
78-
switch CacheService.LastCommit.Adapter {
79-
case "memory":
80-
case "redis", "memcache":
81-
CacheService.LastCommit.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
82-
case "": // disable cache
83-
CacheService.LastCommit.Enabled = false
84-
default:
85-
log.Fatal("Unknown cache.last_commit adapter: %s", CacheService.LastCommit.Adapter)
79+
if !CacheService.LastCommit.UseSeperateCache {
80+
CacheService.LastCommit.Cache = CacheService.Cache
81+
} else {
82+
CacheService.LastCommit.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
83+
switch CacheService.LastCommit.Adapter {
84+
case "memory":
85+
case "redis", "memcache":
86+
CacheService.LastCommit.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
87+
case "": // disable cache
88+
CacheService.LastCommit.Enabled = false
89+
default:
90+
log.Fatal("Unknown cache.last_commit adapter: %s", CacheService.LastCommit.Adapter)
91+
}
8692
}
8793

8894
CacheService.LastCommit.CommitsCount = sec.Key("COMMITS_COUNT").MustInt64(1000)

0 commit comments

Comments
 (0)