mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-31 01:11:23 -05:00
* refactor middleware options Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use ocmemstore micro store implementaiton for token cache Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * refactor ocis store options, support redis sentinel Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * align cache configuration Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * database and tabe are used to build prefixes for inmemory stores Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * add global persistent store options to userlog config Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * log cache errors but continue Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * drup unnecessary type conversion Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * Better description for the default userinfo ttl Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use global cache options for even more caches Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * don't log userinfo cache misses Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * default to stock memory store Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use correct mem store typo string Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * split cache options, doc cleanup Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * mint and write userinfo to cache async Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use hashed token as key Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * go mod tidy Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * update docs Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * update cache store naming Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * bring back depreceted ocis-pkg/store package for backwards compatability Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * update changelog Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * Apply suggestions from code review Co-authored-by: kobergj <jkoberg@owncloud.com> * revert ocis-pkg/cache to store rename Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * add waiting for each step 50 milliseconds * starlack check --------- Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> Co-authored-by: kobergj <jkoberg@owncloud.com> Co-authored-by: Viktor Scharf <scharf.vi@gmail.com>
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"go-micro.dev/v4/store"
|
|
)
|
|
|
|
type typeContextKey struct{}
|
|
|
|
// Store determines the implementation:
|
|
// - "memory", for a in-memory implementation, which is also the default if noone matches
|
|
// - "noop", for a noop store (it does nothing)
|
|
// - "etcd", for etcd
|
|
// - "nats-js" for nats-js, needs to have TTL configured at creation
|
|
// - "redis", for redis
|
|
// - "redis-sentinel", for redis-sentinel
|
|
// - "ocmem", custom in-memory implementation, with fixed size and optimized prefix
|
|
// and suffix search
|
|
func Store(val string) store.Option {
|
|
return func(o *store.Options) {
|
|
if o.Context == nil {
|
|
o.Context = context.Background()
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, typeContextKey{}, val)
|
|
}
|
|
}
|
|
|
|
type sizeContextKey struct{}
|
|
|
|
// Size configures the maximum capacity of the cache for the "ocmem" implementation,
|
|
// in number of items that the cache can hold per table.
|
|
// You can use 5000 to make the cache hold up to 5000 elements.
|
|
// The parameter only affects to the "ocmem" implementation, the rest will ignore it.
|
|
// If an invalid value is used, the default of 512 will be used instead.
|
|
func Size(val int) store.Option {
|
|
return func(o *store.Options) {
|
|
if o.Context == nil {
|
|
o.Context = context.Background()
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, sizeContextKey{}, val)
|
|
}
|
|
}
|
|
|
|
type ttlContextKey struct{}
|
|
|
|
// TTL is the time to live for documents stored in the store
|
|
func TTL(val time.Duration) store.Option {
|
|
return func(o *store.Options) {
|
|
if o.Context == nil {
|
|
o.Context = context.Background()
|
|
}
|
|
|
|
o.Context = context.WithValue(o.Context, ttlContextKey{}, val)
|
|
}
|
|
}
|