Skip to content

Commit

Permalink
cache: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Feb 3, 2022
1 parent f6f01a8 commit 087f7a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions go/ckit/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,18 @@ func (c *Cache) startSizeWatcher() {
for t := range ticker.C {
fi, err := os.Stat(c.Path)
if err != nil {
log.Printf("could not stat file at %s, stopping watch thread", c.Path)
log.Printf("[cache] could not stat file at %s", c.Path)
break
}
if fi.Size() > c.MaxFileSize {
c.Lock()
log.Printf("switching cache at %s to read-only mode at %v", c.Path, t)
log.Printf("[cache] switching %s to read-only mode at %v", c.Path, t.Format(time.RFC3339))
c.readOnly = true
c.Unlock()
break
}
}
log.Printf("[cache] stopping file watcher thread")
}()
}

Expand Down
2 changes: 2 additions & 0 deletions go/ckit/cmd/labed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
enableGzip = flag.Bool("z", false, "enable gzip compression")
enableCache = flag.Bool("c", false, "enable caching of expensive responses")
cacheTriggerDuration = flag.Duration("t", 250*time.Millisecond, "cache trigger duration")
cacheMaxFileSize = flag.Int64("cx", 1<<36, "maximum filesize cache in bytes")
showVersion = flag.Bool("version", false, "show version")
accessLogFile = flag.String("a", "", "path to access log file, do not write access log if empty")
logFile = flag.String("logfile", "", "application log file (stderr if empty)")
Expand Down Expand Up @@ -200,6 +201,7 @@ func main() {
log.Fatal(err)
}
defer c.Close()
c.MaxFileSize = *cacheMaxFileSize
srv.Cache = c
srv.CacheTriggerDuration = *cacheTriggerDuration
}
Expand Down

0 comments on commit 087f7a1

Please sign in to comment.