mongo

package
v0.22.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 6 Imported by: 2

README

Cachego - Mongo driver

The drivers uses go-mgo to store the cache data.

Usage

package main

import (
	"context"
	"log"
	"time"

	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"

	"github.com/faabiosr/cachego/mongo"
)

func main() {
	opts := options.Client().ApplyURI("mongodb://localhost:27017")
	client, _ := mongo.Connect(context.Background(), opts)

	cache := mongo.New(
	    client.Database("cache").Collection("cache"),
    )

	if err := cache.Save("user_id", "1", 10*time.Second); err != nil {
		log.Fatal(err)
	}

	id, err := cache.Fetch("user_id")
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("user id: %s \n", id)
}

Documentation

Overview

Package mongo providers a cache driver that stores the cache in MongoDB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(collection *mongo.Collection) cachego.Cache

New creates an instance of Mongo cache driver

func NewMongoDriver added in v0.17.0

func NewMongoDriver(collection *mongo.Collection) cachego.Cache

NewMongoDriver alias for New.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL