cacheapi

package module
v0.0.0-...-fecb1e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 12 Imported by: 0

README

cacheapi

An alternative BigCache HTTP Server

Build Status GoDoc Docker Cloud Automated build Docker Cloud Build Status

Web API document

https://johejo.github.io/cacheapi/rest/index.html

Installing

go get -u github.com/johejo/cacheapi/cmd/cacheapi

CLI

Usage of cacheapi

  -clearWindow duration
        Interval between removing expired entries (clean up).
  -hardMaxCacheSize int
        HardMaxCacheSize is a limit for cache size in MB. Cache will not allocate more memory than this limit.
  -host string
        The hostname to listen on.
  -lifeWindow duration
        Time after which entry can be evicted. (default 10m0s)
  -maxEntrySize int
        Max size of entry in bytes. (default 500)
  -maxInWindow int
        Max number of entries in life window. (default 600000)
  -port int
        The port to listen on. (default 8888)
  -shards int
        Number of cache shards, value must be a power of two. (default 1024)
  -verbose
        Verbose mode prints information about new memory allocation.
  -version
        Print server version.

Docker Image

Docker Hub

docker run --rm -d -p 8888:8888 johejo/cacheapi

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEnv

func GetEnv(key string, defaultValue string) string

GetEnv wraps os.Getenv with default value.

func GetLogger

func GetLogger() *log.Logger

GetLogger returns logger.

Types

type CacheAPI

type CacheAPI interface {
	Handler() http.Handler
}

CacheAPI abstracts cache for http.Handler.

func NewCacheAPI

func NewCacheAPI(ch CacheHandler) CacheAPI

NewCacheAPI returns a new CacheAPI.

type CacheHandler

type CacheHandler interface {
	PutItem(w http.ResponseWriter, r *http.Request)
	PutItemWithKey(w http.ResponseWriter, r *http.Request)
	GetItem(w http.ResponseWriter, r *http.Request)
	DeleteItem(w http.ResponseWriter, r *http.Request)
	ListItem(w http.ResponseWriter, r *http.Request)
	GetStats(w http.ResponseWriter, r *http.Request)
	GetStatus(w http.ResponseWriter, r *http.Request)
}

CacheHandler combines several methods those implement http.Handler.

func NewCacheHandler

func NewCacheHandler(cs CacheService) CacheHandler

NewCacheHandler returns a new CacheHandler.

type CacheService

type CacheService interface {
	Set(key string, v []byte) error
	SetAndGenerateUUID(v []byte) (string, error)
	Get(key string) (Item, error)
	Delete(key string) error
	List() ([]Item, error)
	Stats() bigcache.Stats
	Len() int
	Capacity() int
}

CacheService provides function for cache.

func NewCacheService

func NewCacheService(config bigcache.Config) CacheService

NewCacheService returns a new CacheService.

type Item

type Item map[string]interface{}

Item represents cache entry with key-value.

type Server

type Server interface {
	Run() error
}

Server represents cacheapi server.

func NewServer

func NewServer(api CacheAPI, host string, port int) Server

NewServer returns a new Server.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL