# README
Cache Adapter implementation for MongoDB
A CacheAdapter
implementation that allows to connect and use a MongoDB database instance.
Usage
Please refer to the following example for the correct usage:
package main
import (
"log"
"time"
mongodbcacheadapters "github.com/tryvium-travels/golang-cache-adapters/mongodb"
)
func main() {
exampleTTL := time.Hour
adapter, err := mongodbcacheadapters.New(exampleTTL)
if err != nil {
// remember to check for errors
log.Fatalf("Adapter initialization error: %s", err)
}
type exampleStruct struct {
Value string
}
exampleKey := "a:mongodb:key"
var exampleValue exampleStruct
err = adapter.Get(exampleKey, &exampleValue)
if err != nil {
// remember to check for errors
log.Fatalf("adapter.Get error: %s", err)
}
exampleKey = "another:mongodb:key"
// nil TTL represents the default value put in the New function
err = adapter.Set(exampleKey, exampleValue, nil)
if err != nil {
// remember to check for errors
log.Fatalf("adapter.Get error: %s", err)
}
}
# Functions
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.
NesSession create a new MongoDB Session adapter.
# Variables
ErrDBConnectionNotCreated will come out if you try to create a database helper over a database connection that is not yet created.
ErrInvalidCollectionName will come out if you try to create a CacheAdapter instance when providing an invalid MongoDB Collection name.
ErrInvalidDatabaseName will come out if you try to create a CacheAdapter instance when providing an invalid MongoDB Database name.
ErrNilClient will come out if you try to create a CacheAdapter instance when providing a nil MongoDB Client instance.
ErrNilCollection will come out if you try to create a CacheAdapter instance when providing a nil MongoDB Collection instance.
ErrNilDatabase will come out if you try to create a CacheAdapter instance when providing a nil MongoDB Database instance.
ErrNilSession will come out if you try to create a CacheSessionAdapter instance when providing a nil MongoDB Session instance.
ErrSessionClosed will come out if you try to do operation on an already closed session.
# Structs
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author