|
@@ -36,32 +36,25 @@ func MustNewModel(url, collection string, c cache.CacheConf, opts ...cache.Optio
|
|
return model
|
|
return model
|
|
}
|
|
}
|
|
|
|
|
|
-// NewNodeModel returns a Model with a cache node.
|
|
|
|
-func NewNodeModel(url, collection string, rds *redis.Redis, opts ...cache.Option) (*Model, error) {
|
|
|
|
- c := cache.NewNode(rds, sharedCalls, stats, mgo.ErrNotFound, opts...)
|
|
|
|
- return createModel(url, collection, c, func(collection mongo.Collection) CachedCollection {
|
|
|
|
- return newCollection(collection, c)
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// NewModel returns a Model with a cache cluster.
|
|
// NewModel returns a Model with a cache cluster.
|
|
func NewModel(url, collection string, conf cache.CacheConf, opts ...cache.Option) (*Model, error) {
|
|
func NewModel(url, collection string, conf cache.CacheConf, opts ...cache.Option) (*Model, error) {
|
|
c := cache.New(conf, sharedCalls, stats, mgo.ErrNotFound, opts...)
|
|
c := cache.New(conf, sharedCalls, stats, mgo.ErrNotFound, opts...)
|
|
- return createModel(url, collection, c, func(collection mongo.Collection) CachedCollection {
|
|
|
|
- return newCollection(collection, c)
|
|
|
|
- })
|
|
|
|
|
|
+ return NewModelWithCache(url, collection, c)
|
|
}
|
|
}
|
|
|
|
|
|
// NewModelWithCache returns a Model with a custom cache.
|
|
// NewModelWithCache returns a Model with a custom cache.
|
|
func NewModelWithCache(url, collection string, c cache.Cache) (*Model, error) {
|
|
func NewModelWithCache(url, collection string, c cache.Cache) (*Model, error) {
|
|
- if c == nil {
|
|
|
|
- log.Fatal("Invalid cache component")
|
|
|
|
- }
|
|
|
|
return createModel(url, collection, c, func(collection mongo.Collection) CachedCollection {
|
|
return createModel(url, collection, c, func(collection mongo.Collection) CachedCollection {
|
|
return newCollection(collection, c)
|
|
return newCollection(collection, c)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// NewNodeModel returns a Model with a cache node.
|
|
|
|
+func NewNodeModel(url, collection string, rds *redis.Redis, opts ...cache.Option) (*Model, error) {
|
|
|
|
+ c := cache.NewNode(rds, sharedCalls, stats, mgo.ErrNotFound, opts...)
|
|
|
|
+ return NewModelWithCache(url, collection, c)
|
|
|
|
+}
|
|
|
|
+
|
|
// Count returns the count of given query.
|
|
// Count returns the count of given query.
|
|
func (mm *Model) Count(query interface{}) (int, error) {
|
|
func (mm *Model) Count(query interface{}) (int, error) {
|
|
return mm.executeInt(func(c CachedCollection) (int, error) {
|
|
return mm.executeInt(func(c CachedCollection) (int, error) {
|