macchiato

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: MIT Imports: 11 Imported by: 0

README

macchiato

Ristretto compatible library designed to use mongo as backend. Is not designed for high performance, just to persist data when you work with ephemeral environments (like Heroku or Google App Engine).

In the future can be great include ristretto to get both functions, but for now it's up to you do the right use :D.

## Example

package main

import (
        "os"
        "log"
        "github.com/GolangResources/macchiato"
)

var cache macchiato.Cache

func main() {
        cache, err := macchiato.NewCache(&macchiato.Config{
                MongoURI: os.Getenv("MONGO_URI"),
                Database: "macchiato",
                Collection: "cache",
        })
        if err != nil {
                panic(err)
        }
	defer cache.Disconnect()

        log.Println("SET: ", cache.Set("TEST", "a", 1))

        result, found := cache.Get("TEST")
        if found {
                log.Println("GET: " + result.(string))
        }

        log.Println("DEL: ", cache.Del("TEST"))
}

How to set TTL

db.cache.createIndex( { "id": 1 }, { unique:true, expireAfterSeconds: 172800 } )

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Gob string
	// contains filtered or unexported fields
}

func NewCache

func NewCache(config *Config) (*Cache, error)

func (*Cache) Del

func (c *Cache) Del(s string) error

func (*Cache) Disconnect added in v0.0.1

func (c *Cache) Disconnect() error

func (*Cache) Get

func (c *Cache) Get(s string) (interface{}, bool)

func (*Cache) RawGet added in v0.0.4

func (c *Cache) RawGet(s string) ([]byte, bool)

func (*Cache) RawSet added in v0.0.4

func (c *Cache) RawSet(s string, i []byte, n int) error

func (*Cache) Register added in v0.0.4

func (c *Cache) Register(i interface{})

func (*Cache) Set

func (c *Cache) Set(s string, i interface{}, n int) error

type CacheCast

type CacheCast struct {
	Interface interface{}
}

type CacheDB

type CacheDB struct {
	ID      string `bson:"id"`
	Content []byte `bson:"content"`
	Type    string `bson:"type"`
}

type Config

type Config struct {
	MongoURI   string
	Database   string
	Collection string
}

Jump to

Keyboard shortcuts

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