memstore

package
v0.0.0-...-c9ee01f Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package memstore provides in-memory data store implementation.

Store

A Store provides in-memory key:value cache that expires after defined duration of time. That duration is defined when a new instance is initialized calling 'memstore.New()' function and it is used to all new stored values.

The Store can manage an application context. Creating an application context its the recommended way to avoid global variables and strict the access to your variables to selected functions.

The lifetime for new values and/or existing values can be modified calling 'SetLifetime()'. The new expiration time will be automatically updated as specified by the scope parameter.

The expiration behaviour can be changed calling 'SetTransient()' to define whether the lifetime of stored value is fixed (transient) or is extended when it is read or written (non-transient).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

A Store provides in-memory key:value cache that expires after defined duration of time.

It is a implementation of Store interface.

func New

func New(d time.Duration, isTransient bool) *Store

New creates a new instance of in-memory Store and defines the default lifetime for new stored items.

If it is specified to not transient then the stored items lifetime are renewed when it is read or written; Otherwise, it is never renewed.

func (*Store) Add

func (s *Store) Add(key string, value interface{}) error

Add adds a new key:value to current store.

Errors: DuplicatedKeyError when requested key already exists.

func (*Store) Count

func (s *Store) Count() (int, error)

Count gets the number of stored values by current instance.

func (*Store) Decrement

func (s *Store) Decrement(key string) (int, error)

Decrement atomically gets the value stored by specified key and decrements it by one. If the key does not exist, it is created.

Errors: InvalidTypeError when the value stored at key is not integer.

func (*Store) DecrementBy

func (s *Store) DecrementBy(key string, value int) (int, error)

DecrementBy atomically gets the value stored by specified key and decrements it by value. If the key does not exist, it is created.

Errors: InvalidTypeError when the value stored at key is not integer.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete deletes the specified key:value.

Errors: InvalidKeyError when requested key could not be found.

func (*Store) Flush

func (s *Store) Flush() error

Flush deletes any cached value into current instance.

func (*Store) Get

func (s *Store) Get(key string, ref interface{}) error

Get gets the value stored by specified key.

Errors: InvalidKeyError when requested key could not be found.

func (*Store) Increment

func (s *Store) Increment(key string) (int, error)

Increment atomically gets the value stored by specified key and increments it by one. If the key does not exist, it is created.

Errors: InvalidTypeError when the value stored at key is not integer.

func (*Store) IncrementBy

func (s *Store) IncrementBy(key string, value int) (int, error)

IncrementBy atomically gets the value stored by specified key and increments it by value. If the key does not exist, it is created.

Errors: InvalidTypeError when the value stored at key is not integer.

func (*Store) Set

func (s *Store) Set(key string, value interface{}) error

Set sets the value of specified key.

Errors: InvalidKeyError when requested key could not be found.

func (*Store) SetLifetime

func (s *Store) SetLifetime(d time.Duration, scope data.LifetimeScope) error

SetLifetime modifies the lifetime for new stored items or for existing items when it is read or written.

Errors: NotSupportedError when ScopeNew is specified.

func (*Store) SetTransient

func (s *Store) SetTransient(value bool)

SetTransient defines whether should extends expiration of stored value when it is read or written.

Jump to

Keyboard shortcuts

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