Skip to content

Commit

Permalink
bring back depreceted ocis-pkg/store package for backwards compatability
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Mar 21, 2023
1 parent 8cf3f31 commit bff4906
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ocis-pkg/store/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cache

import (
"github.com/owncloud/ocis/v2/ocis-pkg/cache"
"go-micro.dev/v4/store"
)

// Create returns a configured key-value micro store
//
// Each microservice (or whatever piece is using the store) should use the
// options available in the interface's operations to choose the right database
// and table to prevent collisions with other microservices.
// Recommended approach is to use "services" or "ocis-pkg" for the database,
// and "services/<service-name>/" or "ocis-pkg/<pkg>/" for the package name.
// Deprecated: use "github.com/owncloud/ocis/v2/ocis-pkg/store" Create
func Create(opts ...store.Option) store.Store {
return cache.Create(opts...)
}
12 changes: 12 additions & 0 deletions ocis-pkg/store/etcd/etcd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package etcd

import (
"github.com/owncloud/ocis/v2/ocis-pkg/cache/etcd"
"go-micro.dev/v4/store"
)

// Create a new go-micro store backed by etcd
// Deprecated: use "github.com/owncloud/ocis/v2/ocis-pkg/store/etcd" NewEtcdStore
func NewEtcdStore(opts ...store.Option) store.Store {
return etcd.NewEtcdStore(opts...)
}
44 changes: 44 additions & 0 deletions ocis-pkg/store/memory/memstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package memory

import (
"context"

"github.com/owncloud/ocis/v2/ocis-pkg/cache/memory"
"go-micro.dev/v4/store"
)

// Prepare a context to be used with the memory implementation. The context
// is used to set up custom parameters to the specific implementation.
// In this case, you can configure the maximum capacity for the MemStore
// implementation as shown below.
// ```
// cache := NewMemStore(
//
// store.WithContext(
// NewContext(
// ctx,
// map[string]interface{}{
// "maxCap": 50,
// },
// ),
// ),
//
// )
// ```
//
// Available options for the MemStore are:
// * "maxCap" -> 512 (int) The maximum number of elements the cache will hold.
// Adding additional elements will remove old elements to ensure we aren't over
// the maximum capacity.
//
// For convenience, this can also be used for the MultiMemStore.
// Deprecated: use "github.com/owncloud/ocis/v2/ocis-pkg/store/memory" NewContext
func NewContext(ctx context.Context, storeParams map[string]interface{}) context.Context {
return memory.NewContext(ctx, storeParams)
}

// Create a new MemStore instance
// Deprecated: use "github.com/owncloud/ocis/v2/ocis-pkg/store/memory" NewMemStore
func NewMemStore(opts ...store.Option) store.Store {
return memory.NewMemStore(opts...)
}
13 changes: 13 additions & 0 deletions ocis-pkg/store/memory/multimemstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package memory

import (
"github.com/owncloud/ocis/v2/ocis-pkg/cache/memory"
"go-micro.dev/v4/store"
)

// Create a new MultiMemStore. A new MemStore will be mapped based on the options.
// A default MemStore will be mapped if no Database and Table aren't used.
// Deprecated: use "github.com/owncloud/ocis/v2/ocis-pkg/store/memory" NewMultiMemStore
func NewMultiMemStore(opts ...store.Option) store.Store {
return memory.NewMultiMemStore(opts...)
}
59 changes: 59 additions & 0 deletions ocis-pkg/store/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cache

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)
}
}

0 comments on commit bff4906

Please sign in to comment.