Sign inSign up

abhi195/go-mem-cache

By abhi195

•Updated almost 6 years ago

In-memory cache with HTTP REST interface

Image
0

147

abhi195/go-mem-cache repository overview

⁠go-mem-cache

A simple in-memory cache with HTTP REST interface.

⁠Cache

⁠usage
package main

import (
	"fmt"
	"time"

	memcache "github.com/abhi195/go-mem-cache"
)

func main() {

	// creating cache with default 30 minutes of TTL which
	// evicts expired entries every 60 minutes
	mc := memcache.New()

	// alternatively you can use NewWith() to
	// create cache with required values
	nmc := memcache.NewWith(1*time.Minute, 2*time.Minute)

	// set key, value
	mc.Set("foo", "bar")

	// get key
	v, exist := mc.Get("foo")
	if exist {
		fmt.Println(v)
	}
}

⁠REST Interface

⁠APIs
GET         /api/v1/cache/{key}
POST        /api/v1/cache/{key} # with plain text body for value

Please import go-mem-cache.postman_collection.json⁠ for sample requests.

⁠Starting HTTP Server
  • Natively
go build -o ./out/cache-server server/*
./out/cache-server
  • Using provided docker image
docker pull abhi195/go-mem-cache
docker run --rm -i -p 8080:8080 abhi195/go-mem-cache
  • Building docker image and running
docker build -t go-mem-cache .
docker run --rm -i -p 8080:8080 go-mem-cache

⁠Future work

Tag summary

Content type

Image

Digest

Size

6.2 MB

Last updated

almost 6 years ago

docker pull abhi195/go-mem-cache