Skip to content

Commit

Permalink
fix: allow cache to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Oct 10, 2023
1 parent ee3e347 commit d5acb92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion common/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ type Cache[T any] struct {
}

func InitCache() {
if Args.Cache == "0" {
return
}

// Create cache folder if not exists
cacheFolderPath := Args.Cache
if _, err := os.Stat(cacheFolderPath); os.IsNotExist(err) && Args.Cache != "0" {
if _, err := os.Stat(cacheFolderPath); os.IsNotExist(err) {
os.MkdirAll(cacheFolderPath, 0700)
}
}
Expand Down
10 changes: 8 additions & 2 deletions store/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *Client) Cache() common.Cache[*Info] {

// Create client cache folder
folder := filepath.Join(common.Args.Cache, "clients", c.Latest.Class)
if _, err := os.Stat(folder); os.IsNotExist(err) && common.Args.Cache != "0" {
if _, err := os.Stat(folder); os.IsNotExist(err) {
os.MkdirAll(folder, 0700)
}

Expand Down Expand Up @@ -227,6 +227,9 @@ func (c *Client) Update() {
}

func (c *Client) Write() {
if common.Args.Cache == "0" {
return
}

// Obtain cache object
cache := c.Cache()
Expand All @@ -250,7 +253,9 @@ func (c *Client) Write() {
}

func (c *Client) Read() *Info {
var info *Info
if common.Args.Cache == "0" {
return c.Latest
}

// Obtain cache object
cache := c.Cache()
Expand All @@ -264,6 +269,7 @@ func (c *Client) Read() *Info {
}

// Parse client info
var info *Info
err = json.Unmarshal([]byte(data), &info)
if err != nil {
log.Warn("Error reading client cache [", c.Latest.Class, "]")
Expand Down

0 comments on commit d5acb92

Please sign in to comment.