safestore

package
v0.0.0-...-8cba18c Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 2 Imported by: 4

README

go-common/safestore

This repository contains the go-common/safestore library.

To install:

go get github.com/ugorji/go-common/safestore

Package Documentation

Package safestore provides a possibly threadsafe key-value cache.

Exported Package API

type I interface{ ... }
type Item struct{ ... }
type T struct{ ... }
    func New(useLock bool) *T

Documentation

Overview

Package safestore provides a possibly threadsafe key-value cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type I

type I interface {
	Put(key interface{}, val interface{}, ttl time.Duration)
	Puts(items ...*Item)
	Removes(keys ...interface{})
	Get(key interface{}) interface{}
	Gets(keys ...interface{}) (v []interface{})
}

I is an interface for a map with expiry support.

type Item

type Item struct {
	Key   interface{}
	Value interface{}
	TTL   time.Duration
}

type T

type T struct {
	// contains filtered or unexported fields
}

The T can be used as a thread-safe map of anything to anything. Use it as a request-scoped cache, etc

Sample Uses:

  • Long-lived shared Cache store
  • Short-lived Request-Scoped Attribute Store ...

A T can be lock enabled or not. If you do not use any goroutines within your code, then create a lock-less T. Purging within a lock-less T is best effort (we don't synchronize anything).

We also support using safestore as a cache.

  • You put in items along with a timestamp and expiry time
  • A goroutine runs which will purge expired entries out of the cache

Note that, even when used as a cache with a TTL, Get will always return the actual value stored.

func New

func New(useLock bool) *T

func (*T) Get

func (rq *T) Get(key interface{}) (v interface{})

func (*T) GetAll

func (rq *T) GetAll() (v [][2]interface{})

func (*T) Gets

func (rq *T) Gets(key ...interface{}) (v []interface{})

func (*T) Gets2

func (rq *T) Gets2(items ...*Item)

func (*T) Incr

func (rq *T) Incr(key interface{}, delta int64, initVal uint64) (newval uint64)

func (*T) Put

func (rq *T) Put(key interface{}, val interface{}, ttl time.Duration)

func (*T) Puts

func (rq *T) Puts(items ...*Item)

func (*T) Removes

func (rq *T) Removes(key ...interface{})

Jump to

Keyboard shortcuts

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