Skip to content

Commit

Permalink
Fix cache time expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Jan 26, 2017
1 parent fcd2c67 commit b9aa9cc
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 9 deletions.
1 change: 0 additions & 1 deletion cmd/clawiod/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func newServer(config root.Configuration) (*server, error) {
s.logger.Error().Log("error", "error registering node")
}
for range time.Tick(time.Second * 5) {
s.logger.Info().Log("msg", "keep alive is issued every 5 seconds: re-registering node")
err = s.registerNode()
if err != nil {
s.logger.Error().Log("error", "error registering node")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func New(logger levels.Levels, cm root.ContextManager, registryDriver root.Regis
func (c *webServiceClient) getAuthenticationURL(ctx context.Context) (string, error) {
u, ok := c.cache.Get("url")
if ok {
c.logger.Info().Log("msg", "authentication-node chosen from cache", "authentication-node-url", u.(string))
return u.(string), nil
}

Expand All @@ -51,7 +52,7 @@ func (c *webServiceClient) getAuthenticationURL(ctx context.Context) (string, er
chosenNode := nodes[rand.Intn(len(nodes))]
c.logger.Info().Log("msg", "authentication-node chosen", "authentication-node-url", chosenNode.URL())
chosenURL := chosenNode.URL() + "/auth"
c.cache.Set("url", chosenURL, cache.NoExpiration)
c.cache.Set("url", chosenURL, cache.DefaultExpiration)
return chosenURL, nil
}

Expand Down
3 changes: 2 additions & 1 deletion root/datawebserviceclient/datawebserviceclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New(logger levels.Levels, cm root.ContextManager, registryDriver root.Regis
func (c *webServiceClient) getDataURL(ctx context.Context) (string, error) {
u, ok := c.cache.Get("url")
if ok {
c.logger.Info().Log("msg", "data-node chosen from cache", "data-node-url", u.(string))
return u.(string), nil
}

Expand All @@ -50,7 +51,7 @@ func (c *webServiceClient) getDataURL(ctx context.Context) (string, error) {
chosenNode := nodes[rand.Intn(len(nodes))]
c.logger.Info().Log("msg", "data-node chosen", "data-node-url", chosenNode.URL())
chosenURL := chosenNode.URL() + "/data"
c.cache.Set("url", chosenURL, cache.NoExpiration)
c.cache.Set("url", chosenURL, cache.DefaultExpiration)
return chosenURL, nil
}
func (c *webServiceClient) UploadFile(ctx context.Context, user root.User, path string, r io.ReadCloser, clientChecksum string) error {
Expand Down
6 changes: 4 additions & 2 deletions root/metadatawebserviceclient/metadatawebserviceclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func New(logger levels.Levels, cm root.ContextManager, registryDriver root.Regis
func (c *webServiceClient) getMetaDataURL(ctx context.Context) (string, error) {
u, ok := c.cache.Get("url")
if ok {
c.logger.Info().Log("msg", "metadata-node chosen from cache", "metadata-node-url", u.(string))
return u.(string), nil
}

Expand All @@ -49,6 +50,7 @@ func (c *webServiceClient) getMetaDataURL(ctx context.Context) (string, error) {
chosenNode := nodes[rand.Intn(len(nodes))]
c.logger.Info().Log("msg", "metadata-node chosen", "metadata-node-url", chosenNode.URL())
chosenURL := chosenNode.URL() + "/meta"
c.cache.Set("url", chosenURL, cache.DefaultExpiration)
return chosenURL, nil
}

Expand Down Expand Up @@ -263,12 +265,12 @@ func (c *webServiceClient) CreateFolder(ctx context.Context, user root.User, pat
return err
}

if res.StatusCode == http.StatusCreated {
if res.StatusCode == http.StatusOK {
return nil
}

c.logger.Error().Log("error", "error creating folder on remote", "httpstatuscode", res.StatusCode)
return internalError(fmt.Sprintf("error creating folder on remote"))
return internalError("error creating folder on remote")
}

type pathReq struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New(logger levels.Levels, registryDriver root.RegistryDriver) (root.WebServ
func (s *service) getProxy(ctx context.Context) (*httputil.ReverseProxy, error) {
p, ok := s.cache.Get("proxy")
if ok {
s.logger.Info().Log("msg", "chosen proxy from cache")
return p.(*httputil.ReverseProxy), nil
}

Expand All @@ -54,7 +55,7 @@ func (s *service) getProxy(ctx context.Context) (*httputil.ReverseProxy, error)
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(u)
s.cache.Set("proxy", proxy, cache.NoExpiration)
s.cache.Set("proxy", proxy, cache.DefaultExpiration)
return proxy, nil
}

Expand Down
3 changes: 2 additions & 1 deletion root/proxieddatawebservice/proxieddatawebservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New(logger levels.Levels, registryDriver root.RegistryDriver) (root.WebServ
func (s *service) getProxy(ctx context.Context) (*httputil.ReverseProxy, error) {
p, ok := s.cache.Get("proxy")
if ok {
s.logger.Info().Log("msg", "chosen proxy from cache")
return p.(*httputil.ReverseProxy), nil
}

Expand All @@ -54,7 +55,7 @@ func (s *service) getProxy(ctx context.Context) (*httputil.ReverseProxy, error)
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(u)
s.cache.Set("proxy", proxy, cache.NoExpiration)
s.cache.Set("proxy", proxy, cache.DefaultExpiration)
return proxy, nil
}

Expand Down
3 changes: 2 additions & 1 deletion root/proxiedmetadatawebservice/proxiedmetadatawebservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New(logger levels.Levels, registryDriver root.RegistryDriver) (root.WebServ
func (s *service) getProxy(ctx context.Context) (*httputil.ReverseProxy, error) {
p, ok := s.cache.Get("proxy")
if ok {
s.logger.Info().Log("msg", "chosen proxy from cache")
return p.(*httputil.ReverseProxy), nil
}

Expand All @@ -54,7 +55,7 @@ func (s *service) getProxy(ctx context.Context) (*httputil.ReverseProxy, error)
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(u)
s.cache.Set("proxy", proxy, cache.NoExpiration)
s.cache.Set("proxy", proxy, cache.DefaultExpiration)
return proxy, nil
}

Expand Down
3 changes: 2 additions & 1 deletion root/proxiedocwebservice/proxiedocwebservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New(logger levels.Levels, registryDriver root.RegistryDriver) (root.WebServ
func (s *service) getProxy(ctx context.Context) (*httputil.ReverseProxy, error) {
p, ok := s.cache.Get("proxy")
if ok {
s.logger.Info().Log("msg", "chosen proxy from cache")
return p.(*httputil.ReverseProxy), nil
}

Expand All @@ -54,7 +55,7 @@ func (s *service) getProxy(ctx context.Context) (*httputil.ReverseProxy, error)
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(u)
s.cache.Set("proxy", proxy, cache.NoExpiration)
s.cache.Set("proxy", proxy, cache.DefaultExpiration)
return proxy, nil
}

Expand Down

0 comments on commit b9aa9cc

Please sign in to comment.