Skip to content

gsingharoy/onecache

Repository files navigation

Onecache

In memory cache implementation in golang.

Build Status codecov

Description

This package contains a simple in memory caching functionality. It supports simply a lookup with a cache key, which contains an expiration contract. the cache storage is periodically cleaned from old expired cached values.

Note This package is useful for small instances (1-2) and not suitable for complex high traffic systems.

Usage

import "github.com/gsingharoy/onecache"

// generate a new cache instance
c := onecache.New()

// Any struct
m := &MyAwesomeStruct{
  ...
}

// set entry to the cache
c.Set("my-awesome-key", m, 3600) // will expire in one hour

// lookup for entry in cache

v, found := c.Find("my-awesome-key")
if !found {
  // logic when cache is missed
}

In case you want the cache to never expire then pass expiresIn as -1

c.Set("my-awesome-key", m, -1)

About

A simple in memory cache for go applications

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages