Skip to content

bmf-san/gowan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gowan

CircleCI GitHub license

A golang inmemory cache store.

Features

  • go 1.15
  • Easy to use
  • Lightweight
  • No external dependencies

Installation

go get github.com/bmf-san/gowan

Examples

package main

import (
	"fmt"
	"net/http"
	"time"

	gowan "github.com/bmf-san/gowan"
)

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

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fk := "first-key"
		sk := "second-key"

		cache.Put(fk, "first-value", time.Now().Add(2*time.Second).UnixNano())
		fmt.Printf("Put first-key: %v\n", fk)
		fmt.Printf("Get first-key: %v\n", cache.Get(fk))

		time.Sleep(10 * time.Second)

		fmt.Print("10 seconds have passed")
		fmt.Printf("Get first-key: %v\n", cache.Get(fk))

		if cache.Get(fk) == nil {
			cache.Put(sk, "second-value", time.Now().Add(100*time.Second).UnixNano())
			fmt.Printf("Put second-key: %v\n", sk)
		}
		fmt.Printf("Get second-key: %v\n", cache.Get(sk))
	})
	http.ListenAndServe(":8080", nil)
}

Contribution

We are always accepting issues, pull requests, and other requests and questions. We look forward to your contribution!

License

This project is licensed under the terms of the MIT license.

Author

bmf - A Web Developer in Japan.