Skip to content

Commit

Permalink
Expose cache ttl config (#3224)
Browse files Browse the repository at this point in the history
* Make the jsoncs3 cache ttl configurable

* Add changelog

* Fix tests
  • Loading branch information
aduffeck committed Sep 12, 2022
1 parent be8e816 commit 0527142
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/expose-cache-ttl-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Make the jsoncs3 share manager cache ttl configurable

We added a new setting to the jsoncs3 share manager which allows to set
the cache ttl.

https://github.com/cs3org/reva/pull/3224
14 changes: 8 additions & 6 deletions pkg/share/manager/jsoncs3/jsoncs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ type config struct {
ServiceUserID string `mapstructure:"service_user_id"`
ServiceUserIdp string `mapstructure:"service_user_idp"`
MachineAuthAPIKey string `mapstructure:"machine_auth_apikey"`
CacheTTL int `mapstructure:"ttl"`
}

// Manager implements a share manager using a cs3 storage backend with local caching
Expand Down Expand Up @@ -147,16 +148,17 @@ func NewDefault(m map[string]interface{}) (share.Manager, error) {
return nil, err
}

return New(s, gc)
return New(s, gc, c.CacheTTL)
}

// New returns a new manager instance.
func New(s metadata.Storage, gc gatewayv1beta1.GatewayAPIClient) (*Manager, error) {
func New(s metadata.Storage, gc gatewayv1beta1.GatewayAPIClient, ttlSeconds int) (*Manager, error) {
ttl := time.Duration(ttlSeconds) * time.Second
return &Manager{
Cache: providercache.New(s, 0*time.Second),
CreatedCache: sharecache.New(s, "users", "created.json", 0*time.Second),
UserReceivedStates: receivedsharecache.New(s, 0*time.Second),
GroupReceivedCache: sharecache.New(s, "groups", "received.json", 0*time.Second),
Cache: providercache.New(s, ttl),
CreatedCache: sharecache.New(s, "users", "created.json", ttl),
UserReceivedStates: receivedsharecache.New(s, ttl),
GroupReceivedCache: sharecache.New(s, "groups", "received.json", ttl),
storage: s,
gateway: gc,
}, nil
Expand Down
20 changes: 10 additions & 10 deletions pkg/share/manager/jsoncs3/jsoncs3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ var _ = Describe("Jsoncs3", func() {
Expect(err).ToNot(HaveOccurred())

client = &mocks.GatewayAPIClient{}
m, err = jsoncs3.New(storage, client)
m, err = jsoncs3.New(storage, client, 0)
Expect(err).ToNot(HaveOccurred())
})

Expand Down Expand Up @@ -251,7 +251,7 @@ var _ = Describe("Jsoncs3", func() {
})
Expect(s).ToNot(BeNil())

m, err = jsoncs3.New(storage, nil) // Reset in-memory cache
m, err = jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

s = shareBykey(&collaboration.ShareKey{
Expand Down Expand Up @@ -445,7 +445,7 @@ var _ = Describe("Jsoncs3", func() {
})

It("loads the cache when it doesn't have an entry", func() {
m, err := jsoncs3.New(storage, nil) // Reset in-memory cache
m, err := jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

s, err := m.GetShare(ctx, shareRef)
Expand Down Expand Up @@ -505,7 +505,7 @@ var _ = Describe("Jsoncs3", func() {
})
Expect(err).ToNot(HaveOccurred())

m, err = jsoncs3.New(storage, nil) // Reset in-memory cache
m, err = jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

s, err := m.GetShare(ctx, &collaboration.ShareReference{
Expand Down Expand Up @@ -618,7 +618,7 @@ var _ = Describe("Jsoncs3", func() {
Expect(us).ToNot(BeNil())
Expect(us.GetPermissions().GetPermissions().InitiateFileUpload).To(BeTrue())

m, err = jsoncs3.New(storage, nil) // Reset in-memory cache
m, err = jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

s = shareBykey(&collaboration.ShareKey{
Expand Down Expand Up @@ -749,7 +749,7 @@ var _ = Describe("Jsoncs3", func() {
})

It("syncronizes the user received cache before listing", func() {
m, err := jsoncs3.New(storage, nil) // Reset in-memory cache
m, err := jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

received, err := m.ListReceivedShares(granteeCtx, []*collaboration.Filter{})
Expand Down Expand Up @@ -817,7 +817,7 @@ var _ = Describe("Jsoncs3", func() {
})

It("syncronizes the group received cache before listing", func() {
m, err := jsoncs3.New(storage, nil) // Reset in-memory cache
m, err := jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

received, err := m.ListReceivedShares(granteeCtx, []*collaboration.Filter{})
Expand Down Expand Up @@ -861,7 +861,7 @@ var _ = Describe("Jsoncs3", func() {
})

It("syncs the cache", func() {
m, err := jsoncs3.New(storage, nil) // Reset in-memory cache
m, err := jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

rs, err := m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Expand Down Expand Up @@ -895,7 +895,7 @@ var _ = Describe("Jsoncs3", func() {
})

It("syncs the cache", func() {
m, err := jsoncs3.New(storage, nil) // Reset in-memory cache
m, err := jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

rs, err := m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Expand Down Expand Up @@ -1018,7 +1018,7 @@ var _ = Describe("Jsoncs3", func() {
Expect(err).ToNot(HaveOccurred())
Expect(rs.State).To(Equal(collaboration.ShareState_SHARE_STATE_ACCEPTED))

m, err := jsoncs3.New(storage, nil) // Reset in-memory cache
m, err := jsoncs3.New(storage, nil, 0) // Reset in-memory cache
Expect(err).ToNot(HaveOccurred())

rs, err = m.GetReceivedShare(granteeCtx, &collaboration.ShareReference{
Expand Down

0 comments on commit 0527142

Please sign in to comment.