mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-03 02:39:52 -06:00
35 lines
770 B
Go
35 lines
770 B
Go
package roles
|
|
|
|
import (
|
|
"time"
|
|
"github.com/owncloud/ocis/ocis-pkg/sync"
|
|
settings "github.com/owncloud/ocis/settings/pkg/proto/v0"
|
|
)
|
|
|
|
// cache is a cache implementation for roles, keyed by roleIDs.
|
|
type cache struct {
|
|
sc sync.Cache
|
|
ttl time.Duration
|
|
}
|
|
|
|
// newCache returns a new instance of Cache.
|
|
func newCache(capacity int, ttl time.Duration) cache {
|
|
return cache{
|
|
ttl: ttl,
|
|
sc: sync.NewCache(capacity),
|
|
}
|
|
}
|
|
|
|
// get gets a role-bundle by a given `roleID`.
|
|
func (c *cache) get(roleID string) *settings.Bundle {
|
|
if ce := c.sc.Load(roleID); ce != nil {
|
|
return ce.V.(*settings.Bundle)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// set sets a roleID / role-bundle.
|
|
func (c *cache) set(roleID string, value *settings.Bundle) {
|
|
c.sc.Store(roleID, value, time.Now().Add(c.ttl))
|
|
} |