-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bring back depreceted ocis-pkg/store package for backwards compatability
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
- Loading branch information
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |