store

package
v0.0.0-...-3b86d9c Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: Apache-2.0 Imports: 2 Imported by: 2

README

dcos-go/store

A simple, local, and goroutine-safe in-memory key-value store.

Overview

dcos-go/store is a simple, local, in-memory key-value store for caching objects for short periods of time. The motivation for this project was the HTTP producer in dcos-metrics where we have a need to cache a "snapshot" of a given agent's metrics until the next polling interval.

Usage

import "github.com/dcos/dcos-go/store"

// Basic usage
s := store.New()
s.Set("foo", "fooval")
s.Set("bar", "barval")

s.Get("foo") // fooval
s.Objects()  // map[foo:{fooval} bar:{barval}]
s.Size()     // 1
s.Delete("foo")
s.Purge()

// Advanced usage
newMap := make(map[string]interface{})
newMap["foo2"] = "fooval2"
newMap["bar2"] = "barval2"

// Replace (supplant) all objects in the cache with thsoe in newMap
s.Supplant(newMap) // map[foo2:{fooval2} bar2:{barval2}]

Documentation

Overview

Package store is a simple, local, goroutine-safe in-memory key-value store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store interface {
	Delete(string)
	Get(string) (interface{}, bool)
	GetByRegex(string) (map[string]interface{}, error)
	Objects() map[string]interface{}
	Purge()
	Set(string, interface{})
	Size() int
	Supplant(map[string]interface{})
}

Store represents the interface and available methods of the dcos-go/store package.

func New

func New() Store

New creates a new, basic, in-memory store. The caller must handle all Set() and Delete() operations by itself; that is to say, there is no concept of a maximum size or expiration on stored objects.

Jump to

Keyboard shortcuts

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