Documentation ¶
Overview ¶
Package mongodbcacheadapters contains the implementations of CacheAdapter and CacheSessionAdapter for a MongoDB instance based cache, along with some helper methods to create instances.
Index ¶
- Variables
- func New(client MongoClient, databaseName string, collectionName string, ...) (cacheadapters.CacheAdapter, error)
- func NewSession(collection MongoCollection, defaultTTL time.Duration) (cacheadapters.CacheSessionAdapter, error)
- type MongoClient
- type MongoCollection
- type MongoDBAdapter
- func (ma *MongoDBAdapter) Delete(key string) error
- func (ma *MongoDBAdapter) Get(key string, objectRef interface{}) error
- func (ma *MongoDBAdapter) OpenSession() (cacheadapters.CacheSessionAdapter, error)
- func (ma *MongoDBAdapter) Set(key string, object interface{}, TTL *time.Duration) error
- func (ma *MongoDBAdapter) SetTTL(key string, newTTL time.Duration) error
- type MongoDBSessionAdapter
- func (msa *MongoDBSessionAdapter) Close() error
- func (msa *MongoDBSessionAdapter) Delete(key string) error
- func (msa *MongoDBSessionAdapter) Get(key string, objectRef interface{}) error
- func (msa *MongoDBSessionAdapter) Set(key string, object interface{}, TTL *time.Duration) error
- func (msa *MongoDBSessionAdapter) SetTTL(key string, newTTL time.Duration) error
- type MongoDatabase
- type MongoSession
Constants ¶
This section is empty.
Variables ¶
View Source
var ( //ErrDBConnectionNotCreated will come out if you try to create a database helper // over a database connection that is not yet created. ErrDBConnectionNotCreated = fmt.Errorf("cannot create a database helper instance over a never-created database connection") //ErrNilClient will come out if you try to create a CacheAdapter instance // when providing a nil MongoDB Client instance ErrNilClient = fmt.Errorf("cannot create the adapter with nil MongoDB Client instance") //ErrInvalidDatabaseName will come out if you try to create a CacheAdapter instance // when providing an invalid MongoDB Database name ErrInvalidDatabaseName = fmt.Errorf("cannot create the adapter with invalid MongoDB Database name") //ErrInvalidCollectionName will come out if you try to create a CacheAdapter instance // when providing an invalid MongoDB Collection name ErrInvalidCollectionName = fmt.Errorf("cannot create the adapter with invalid MongoDB Collection name") //ErrNilDatabase will come out if you try to create a CacheAdapter instance // when providing a nil MongoDB Database instance ErrNilDatabase = fmt.Errorf("cannot create the adapter with nil MongoDB Database instance") //ErrNilCollection will come out if you try to create a CacheAdapter instance // when providing a nil MongoDB Collection instance ErrNilCollection = fmt.Errorf("cannot create the adapter with nil MongoDB Collection instance") //ErrNilSession will come out if you try to create a CacheSessionAdapter instance // when providing a nil MongoDB Session instance ErrNilSession = fmt.Errorf("cannot create the session adapter with nil MongoDB Session instance") //ErrSessionClosed will come out if you try to do operation on an already // closed session ErrSessionClosed = fmt.Errorf("cannot use a closed connection") )
Functions ¶
func New ¶
func New(client MongoClient, databaseName string, collectionName string, defaultTTL time.Duration) (cacheadapters.CacheAdapter, error)
NesSession create a new MongoDB Cache adapter from an existing MongoDB client and the name of the database and the collection, with a given default TTL.
func NewSession ¶
func NewSession(collection MongoCollection, defaultTTL time.Duration) (cacheadapters.CacheSessionAdapter, error)
NesSession create a new MongoDB Session adapter
Types ¶
type MongoClient ¶
type MongoCollection ¶
type MongoCollection interface { FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) }
type MongoDBAdapter ¶
type MongoDBAdapter struct {
// contains filtered or unexported fields
}
func (*MongoDBAdapter) Delete ¶
func (ma *MongoDBAdapter) Delete(key string) error
Delete deletes a key from the cache.
func (*MongoDBAdapter) Get ¶
func (ma *MongoDBAdapter) Get(key string, objectRef interface{}) error
Get obtains a value from the cache using a key, then tries to unmarshal it into the object reference passed as parameter.
func (*MongoDBAdapter) OpenSession ¶
func (ma *MongoDBAdapter) OpenSession() (cacheadapters.CacheSessionAdapter, error)
type MongoDBSessionAdapter ¶
type MongoDBSessionAdapter struct {
// contains filtered or unexported fields
}
func (*MongoDBSessionAdapter) Close ¶
func (msa *MongoDBSessionAdapter) Close() error
Close closes the Cache Session.
func (*MongoDBSessionAdapter) Delete ¶
func (msa *MongoDBSessionAdapter) Delete(key string) error
Delete deletes a key from the cache.
func (*MongoDBSessionAdapter) Get ¶
func (msa *MongoDBSessionAdapter) Get(key string, objectRef interface{}) error
type MongoDatabase ¶
type MongoDatabase interface {
Collection(name string, opts ...*options.CollectionOptions) *mongo.Collection
}
type MongoSession ¶
Click to show internal directories.
Click to hide internal directories.