Skip to content

Commit

Permalink
Remove OCS share cache default TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Apr 26, 2021
1 parent 83bf50a commit 9aee85e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 0 additions & 4 deletions internal/http/services/owncloud/ocs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,5 @@ func (c *Config) Init() {
c.ResourceInfoCacheSize = 1000000
}

if c.ResourceInfoCacheTTL == 0 {
c.ResourceInfoCacheTTL = 86400
}

c.GatewaySvc = sharedconf.GetGatewaySVC(c.GatewaySvc)
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh
var info *provider.ResourceInfo
for _, share := range res.GetShare() {
key := wrapResourceID(share.ResourceId)
if infoIf, err := h.resourceInfoCache.Get(key); err == nil {
if infoIf, err := h.resourceInfoCache.Get(key); h.resourceInfoCacheTTL > 0 && err == nil {
log.Debug().Msgf("cache hit for resource %+v", share.ResourceId)
info = infoIf.(*provider.ResourceInfo)
} else {
Expand All @@ -181,7 +181,9 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh
continue
}
info = statResponse.Info
_ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL)
if h.resourceInfoCacheTTL > 0 {
_ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL)
}
}

sData := conversions.PublicShare2ShareData(share, r, h.publicURL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin

var info *provider.ResourceInfo
key := wrapResourceID(resourceID)
if infoIf, err := h.resourceInfoCache.Get(key); err == nil {
if infoIf, err := h.resourceInfoCache.Get(key); h.resourceInfoCacheTTL > 0 && err == nil {
logger.Debug().Msgf("cache hit for resource %+v", resourceID)
info = infoIf.(*provider.ResourceInfo)
} else {
Expand All @@ -425,7 +425,9 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin
return
}
info = statResponse.Info
_ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL)
if h.resourceInfoCacheTTL > 0 {
_ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL)
}
}

err = h.addFileInfo(ctx, share, info)
Expand Down Expand Up @@ -609,7 +611,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {
// prefix the path with the owners home, because ocs share requests are relative to the home dir
target := path.Join(h.homeNamespace, r.FormValue("path"))

if infoIf, err := h.resourceInfoCache.Get(target); err == nil {
if infoIf, err := h.resourceInfoCache.Get(target); h.resourceInfoCacheTTL > 0 && err == nil {
logger.Debug().Msgf("cache hit for resource %+v", target)
pinfo = infoIf.(*provider.ResourceInfo)
} else {
Expand Down Expand Up @@ -640,7 +642,9 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {
}

pinfo = statRes.GetInfo()
_ = h.resourceInfoCache.SetWithExpire(target, pinfo, time.Second*h.resourceInfoCacheTTL)
if h.resourceInfoCacheTTL > 0 {
_ = h.resourceInfoCache.SetWithExpire(target, pinfo, time.Second*h.resourceInfoCacheTTL)
}
}
}

Expand Down Expand Up @@ -682,7 +686,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {
info = pinfo
} else {
key := wrapResourceID(rs.Share.ResourceId)
if infoIf, err := h.resourceInfoCache.Get(key); err == nil {
if infoIf, err := h.resourceInfoCache.Get(key); h.resourceInfoCacheTTL > 0 && err == nil {
logger.Debug().Msgf("cache hit for resource %+v", rs.Share.ResourceId)
info = infoIf.(*provider.ResourceInfo)
} else {
Expand All @@ -702,7 +706,9 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {
}

info = statRes.GetInfo()
_ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL)
if h.resourceInfoCacheTTL > 0 {
_ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL)
}
}
}

Expand Down Expand Up @@ -802,7 +808,7 @@ func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix stri
}

target := path.Join(prefix, r.FormValue("path"))
if infoIf, err := h.resourceInfoCache.Get(target); err == nil {
if infoIf, err := h.resourceInfoCache.Get(target); h.resourceInfoCacheTTL > 0 && err == nil {
info = infoIf.(*provider.ResourceInfo)
} else {
statReq := &provider.StatRequest{
Expand Down Expand Up @@ -830,7 +836,9 @@ func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix stri
}

info = res.Info
_ = h.resourceInfoCache.SetWithExpire(target, info, time.Second*h.resourceInfoCacheTTL)
if h.resourceInfoCacheTTL > 0 {
_ = h.resourceInfoCache.SetWithExpire(target, info, time.Second*h.resourceInfoCacheTTL)
}
}

collaborationFilters = append(collaborationFilters, &collaboration.ListSharesRequest_Filter{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.ListS

var info *provider.ResourceInfo
key := wrapResourceID(s.ResourceId)
if infoIf, err := h.resourceInfoCache.Get(key); err == nil {
if infoIf, err := h.resourceInfoCache.Get(key); h.resourceInfoCacheTTL > 0 && err == nil {
log.Debug().Msgf("cache hit for resource %+v", s.ResourceId)
info = infoIf.(*provider.ResourceInfo)
} else {
Expand All @@ -198,7 +198,9 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.ListS
continue
}
info = statResponse.Info
_ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL)
if h.resourceInfoCacheTTL > 0 {
_ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL)
}
}

if err := h.addFileInfo(ctx, data, info); err != nil {
Expand Down

0 comments on commit 9aee85e

Please sign in to comment.