Skip to content

akulnurislam/simplecache

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simplecache

Simple cache abstraction for Golang

Supported cache

  • In Memory
  • Redis
  • LRU

Quick Start

Installation $ go get github.com/akulnurislam/simplecache

Usage

Interface:

type Cache interface {
	Set(ctx context.Context, key string, value interface{}, expiration int) error
	Get(ctx context.Context, key string) ([]byte, error)
	GetObject(ctx context.Context, key string, doc interface{}) error
	GetString(ctx context.Context, key string) (string, error)
	GetInt(ctx context.Context, key string) (int64, error)
	GetFloat(ctx context.Context, key string) (float64, error)
	Exist(ctx context.Context, key string) bool
	Delete(ctx context.Context, key string) error
	RemainingTime(ctx context.Context, key string) int
	Close() error
}

Example:

package main

import (
	cache "github.com/akulnurislam/simplecache"
	_ "github.com/akulnurislam/simplecache/mem"
	_ "github.com/akulnurislam/simplecache/redis"
	_ "github.com/akulnurislam/simplecache/lru"
)

func main() {
	// Use in-memory store
	memcache, _ := cache.New("mem://")
	rediscache, _ := cache.New("redis://<user>:<pass>@localhost:6379/prefix")
	lru, _ := cache.New("lru://local/1024")
}

About

Simple cache abstraction for Golang

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Go 100.0%