Skip to content

faabiosr/cachego

Folders and files

NameName
Last commit message
Last commit date

Latest commit

169cdf9 · Apr 14, 2024

History

89 Commits
Mar 18, 2023
May 7, 2023
Feb 21, 2023
May 10, 2023
Feb 21, 2023
May 7, 2023
Mar 18, 2023
May 7, 2023
Feb 21, 2023
Mar 13, 2020
Feb 21, 2023
May 8, 2019
Oct 5, 2016
Feb 21, 2023
Jun 23, 2023
Jun 10, 2022
Feb 21, 2023
Feb 22, 2023
Jun 14, 2020
Jun 14, 2020
Apr 14, 2024
Apr 14, 2024

Repository files navigation

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.