Documentation
¶
Index ¶
- Variables
- func CacheWrapper(ctx context.Context, collectionName string, cacheKey string, ...) error
- func ConnectDatabase(cfg models.DatabaseConfig) error
- func GenerateCacheKey(collectionName string, filter interface{}) (string, error)
- func GetCollection(name string) *mongo.Collection
- func InvalidateCache(ctx context.Context, collectionName string, cacheKey string, ...) error
- func UpdateCache(ctx context.Context, collectionName string, cacheKey string, ...) error
- type CollectionInterface
- type SingoleResultInterface
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Client *mongo.Client
)
Functions ¶
func CacheWrapper ¶
func CacheWrapper(ctx context.Context, collectionName string, cacheKey string, filter interface{}, projection interface{}, result interface{}) error
CacheWrapper is a helper function to fetch data from MongoDB and cache the result
func ConnectDatabase ¶
func ConnectDatabase(cfg models.DatabaseConfig) error
func GenerateCacheKey ¶
func GetCollection ¶
func GetCollection(name string) *mongo.Collection
Helper function to simplify getting data. example: clientsCollection := GetCollection("clients")
func InvalidateCache ¶
func InvalidateCache(ctx context.Context, collectionName string, cacheKey string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) error
Cache Invalidation - Deletes the cached entry after updating the database
Types ¶
type CollectionInterface ¶
type CollectionInterface interface { InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (cur *mongo.Cursor, err error) }
CollectionInterface defines the methods used from mongo.Collection
type SingoleResultInterface ¶
CollectionInterface defines the methods used from mongo.Collection
Click to show internal directories.
Click to hide internal directories.