Skip to content

Commit d3a7362

Browse files
lafrikslunny
authored andcommitted
Revert Enabled back
1 parent c21b16a commit d3a7362

File tree

7 files changed

+22
-9
lines changed

7 files changed

+22
-9
lines changed

custom/conf/app.ini.sample

+4
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@ SENDMAIL_PATH = sendmail
632632
SENDMAIL_ARGS =
633633

634634
[cache]
635+
; if the cache enabled
636+
ENABLED = true
635637
; Either "memory", "redis", or "memcache", default is "memory"
636638
ADAPTER = memory
637639
; For "memory" only, GC interval in seconds, default is 60
@@ -646,6 +648,8 @@ ITEM_TTL = 16h
646648

647649
; Last commit cache
648650
[cache.last_commit]
651+
; if the cache enabled
652+
ENABLED = true
649653
; Time to keep items in cache if not used, default is 16 hours.
650654
; Setting it to 0 disables caching
651655
ITEM_TTL = 16h

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

+2
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ relation to port exhaustion.
383383

384384
## Cache (`cache`)
385385

386+
- `ENABLED`: **true**: Enable the cache.
386387
- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`.
387388
- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only.
388389
- `HOST`: **\<empty\>**: Connection string for `redis` and `memcache`.
@@ -392,6 +393,7 @@ relation to port exhaustion.
392393

393394
## Cache - LastCommitCache settings (`cache.last_commit`)
394395

396+
- `ENABLED`: **true**: Enable the cache.
395397
- `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching.
396398
- `COMMITS_COUNT`: **1000**: Only enable the cache when repository's commits count great than.
397399

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

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ menu:
148148

149149
## Cache (`cache`)
150150

151+
- `ENABLED`: **true**: 是否启用。
151152
- `ADAPTER`: **memory**: 缓存引擎,可以为 `memory`, `redis``memcache`
152153
- `INTERVAL`: **60**: 只对内存缓存有效,GC间隔,单位秒。
153154
- `HOST`: **\<empty\>**: 针对redis和memcache有效,主机地址和端口。
@@ -157,6 +158,7 @@ menu:
157158

158159
## Cache - LastCommitCache settings (`cache.last_commit`)
159160

161+
- `ENABLED`: **true**: 是否启用。
160162
- `ITEM_TTL`: **86400h**: 缓存项目失效时间,设置为 0 则禁用缓存。
161163
- `COMMITS_COUNT`: **1000**: 仅当仓库的提交数大于时才启用缓存。
162164

modules/cache/cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func newCache(cacheConfig setting.Cache) (mc.Cache, error) {
3232
func NewContext() error {
3333
var err error
3434

35-
if conn == nil && setting.CacheService.TTL > 0 {
35+
if conn == nil && setting.CacheService.Enabled {
3636
if conn, err = newCache(setting.CacheService.Cache); err != nil {
3737
return err
3838
}

modules/cache/last_commit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewLastCommitCache(repoPath string, gitRepo *git.Repository, ttl int64) *La
3636

3737
// Get get the last commit information by commit id and entry path
3838
func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) {
39-
v := c.Cache.Get(fmt.Sprintf("lastcommit:%s:%s:%s", c.repoPath, ref, entryPath))
39+
v := c.Cache.Get(fmt.Sprintf("last_commit:%s:%s:%s", c.repoPath, ref, entryPath))
4040
if vs, ok := v.(string); ok {
4141
log.Trace("LastCommitCache hit level 1: [%s:%s:%s]", ref, entryPath, vs)
4242
if commit, ok := c.commitCache[vs]; ok {
@@ -60,5 +60,5 @@ func (c LastCommitCache) Get(ref, entryPath string) (*object.Commit, error) {
6060
// Put put the last commit id with commit and entry path
6161
func (c LastCommitCache) Put(ref, entryPath, commitID string) error {
6262
log.Trace("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID)
63-
return c.Cache.Put(fmt.Sprintf("lastcommit:%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl)
63+
return c.Cache.Put(fmt.Sprintf("last_commit:%s:%s:%s", c.repoPath, ref, entryPath), commitID, c.ttl)
6464
}

modules/setting/cache.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
// Cache represents cache settings
1515
type Cache struct {
16+
Enabled bool
1617
Adapter string
1718
Interval int
1819
Conn string
@@ -25,19 +26,23 @@ var (
2526
Cache
2627

2728
LastCommit struct {
29+
Enabled bool
2830
TTL time.Duration `ini:"ITEM_TTL"`
2931
CommitsCount int64
3032
} `ini:"cache.last_commit"`
3133
}{
3234
Cache: Cache{
35+
Enabled: true,
3336
Adapter: "memory",
3437
Interval: 60,
3538
TTL: 16 * time.Hour,
3639
},
3740
LastCommit: struct {
41+
Enabled bool
3842
TTL time.Duration `ini:"ITEM_TTL"`
3943
CommitsCount int64
4044
}{
45+
Enabled: true,
4146
TTL: 16 * time.Hour,
4247
CommitsCount: 1000,
4348
},
@@ -56,23 +61,23 @@ func newCacheService() {
5661
case "redis", "memcache":
5762
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
5863
case "": // disable cache
59-
CacheService.TTL = 0
64+
CacheService.Enabled = false
6065
default:
6166
log.Fatal("Unknown cache adapter: %s", CacheService.Adapter)
6267
}
6368

64-
if CacheService.TTL > 0 {
69+
if CacheService.Enabled {
6570
log.Info("Cache Service Enabled")
6671
}
6772

6873
sec = Cfg.Section("cache.last_commit")
69-
if CacheService.TTL == 0 {
70-
CacheService.LastCommit.TTL = 0
74+
if !CacheService.Enabled {
75+
CacheService.LastCommit.Enabled = false
7176
}
7277

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

75-
if CacheService.LastCommit.TTL > 0 {
80+
if CacheService.LastCommit.Enabled {
7681
log.Info("Last Commit Cache Service Enabled")
7782
}
7883
}

routers/repo/view.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
5151
entries.CustomSort(base.NaturalSortLess)
5252

5353
var c git.LastCommitCache
54-
if setting.CacheService.LastCommit.TTL > 0 && ctx.Repo.CommitsCount >= setting.CacheService.LastCommit.CommitsCount {
54+
if setting.CacheService.LastCommit.Enabled && ctx.Repo.CommitsCount >= setting.CacheService.LastCommit.CommitsCount {
5555
c = cache.NewLastCommitCache(ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, int64(setting.CacheService.LastCommit.TTL.Seconds()))
5656
}
5757

0 commit comments

Comments
 (0)