Categorygithub.com/faabiosr/cachego
modulepackage
0.22.3
Repository: https://github.com/faabiosr/cachego.git
Documentation: pkg.go.dev

# README

Cachego

Codecov branch GoDoc Go Report Card License

Simple interface for caching

Installation

Cachego requires Go 1.18 or later.

go get github.com/faabiosr/cachego

Usage

package main

import (
	"log"
	"time"

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

func main() {
	cache := sync.New()

	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)

	keys := cache.FetchMulti([]string{"user_id", "user_name"})

	for k, v := range keys {
		log.Printf("%s: %s\n", k, v)
	}

	if cache.Contains("user_name") {
		cache.Delete("user_name")
	}

	if _, err := cache.Fetch("user_name"); err != nil {
		log.Printf("%v\n", err)
	}

	if err := cache.Flush(); err != nil {
		log.Fatal(err)
	}
}

Supported drivers

Documentation

Read the full documentation at https://pkg.go.dev/github.com/faabiosr/cachego.

Development

Requirements

Makefile

// Clean up
$ make clean

//Run tests and generates html coverage file
$ make cover

// Up the docker containers for testing
$ make docker

// Format all go files
$ make fmt

//Run linters
$ make lint

// Run tests
$ make test

License

This project is released under the MIT licence. See LICENSE for more details.

# Packages

Package bolt providers a cache driver that stores the cache using BoltDB.
Package chain provides chaining cache drivers operations, in case of failure the driver try to apply using the next driver informed, until fail.
Package file providers a cache driver that stores the cache content in files.
Package memcached providers a cache driver that stores the cache in Memcached.
Package mongo providers a cache driver that stores the cache in MongoDB.
Package redis providers a cache driver that stores the cache in Redis.
Package sqlite3 providers a cache driver that stores the cache in SQLite3.
Package sync providers a cache driver that uses standard golang sync.Map.

# Constants

ErrCacheExpired returns an error when the cache key was expired.
ErrDecode returns an errors when decode fails.
ErrDelete returns an error when deletion fails.
ErrFlush returns an error when flush fails.
ErrSave returns an error when save fails.

# Interfaces

No description provided by the author