data

package module
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: 2 Imported by: 4

README

Data

Data is a library for the Go Programming Language. It defines interfaces shared by other packages that implement data storages.

Status

Build Status Coverage Status GoDoc

Features

  • Store interface for objects that store expirable values.
  • memstore.Store type to store expirable values in-memory.
  • mongostore.Store type to store expirable values in MongoDB.

Installation

This library provides two Store Implementations: in-memory and MongoDB.

In-Memory

To install in-memory implementation of Store run the following command:

go get gopkg.in/raiqub/data.v0/memstore

To import this package, add the following line to your code:

import "gopkg.in/raiqub/data.v0/memstore"
MongoDB

To install MongoDB implementation of Store run the following command:

go get gopkg.in/raiqub/data.v0/mongostore

To import this package, add the following line to your code:

import "gopkg.in/raiqub/data.v0/memstore"

Examples

Examples can be found on library documentation.

Running tests

The tests can be run via the provided Bash script:

./test.sh

License

raiqub/data is made available under the Apache Version 2.0 License.

Documentation

Overview

Package data defines interfaces shared by other packages that implement data storages.

Store

Store is the inteface implemented by an object that provides a storage for expirable values.

A Store object 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).

LifetimeScope

A LifetimeScope which stored values will be affected by lifetime change.

Use 'ScopeAll' to apply the new lifetime for existing values and the ones that will be created on the future.

Use 'ScopeNewAndUpdated' to apply the new lifetime for existing values when they are read or written, and the ones that will be created on the future.

Use 'ScopeNew' to apply the new lifetime only for the ones that will be created on the future.

Index

Constants

View Source
const (
	// ScopeAll defines that the new lifetime value should be applied for new
	// and existing store items.
	ScopeAll = LifetimeScope(0)

	// ScopeNewAndUpdated defines that new lifetime value should be applied for
	// new and future updates on stored items.
	// A stored item is updated when it is read or written.
	ScopeNewAndUpdated = LifetimeScope(1)

	// ScopeNew defines that new lifetime value should be applied for new store
	// items.
	ScopeNew = LifetimeScope(2)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type InvalidTypeError

type InvalidTypeError struct {
	Value interface{}
}

A InvalidTypeError represents an error when value type is different than expected.

func NewInvalidTypeError

func NewInvalidTypeError(value interface{}) InvalidTypeError

NewInvalidTypeError returns a new instance of InvalidTypeError.

func (InvalidTypeError) Error

func (e InvalidTypeError) Error() string

Error returns string representation of current instance error.

type LifetimeScope

type LifetimeScope int

A LifetimeScope its a value which defines scope to apply new lifetime value.

type Store

type Store interface {
	// Add adds a new key:value to current store.
	//
	// Errors:
	// DuplicatedKeyError when requested key already exists.
	Add(key string, value interface{}) error

	// Count gets the number of stored values by current instance.
	//
	// Errors:
	// NotSupportedError when current method cannot be implemented.
	Count() (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.
	Decrement(key string) (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.
	DecrementBy(key string, value int) (int, error)

	// Delete deletes the specified value.
	//
	// Errors:
	// InvalidKeyError when requested key could not be found.
	Delete(key string) error

	// Flush deletes any cached value into current instance.
	//
	// Errors:
	// NotSupportedError when current method cannot be implemented.
	Flush() error

	// Get gets the value stored by specified key and stores the result in the
	// value pointed to by ref.
	//
	// Errors:
	// InvalidKeyError when requested key could not be found.
	Get(key string, ref interface{}) error

	// Increment atomically gets the value stored by specified key and
	// increments it by one. If the key does not exist, it is created.
	Increment(key string) (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.
	IncrementBy(key string, value int) (int, error)

	// Set sets the value of specified key.
	//
	// Errors:
	// InvalidKeyError when requested key could not be found.
	Set(key string, value interface{}) error

	// SetLifetime modifies the lifetime for a especified scope.
	//
	// Errors:
	// NotSupportedError when current method cannot be implemented.
	SetLifetime(time.Duration, LifetimeScope) error

	// SetTransient defines whether should extends expiration of stored value
	// when it is read or written.
	SetTransient(bool)
}

A Store represents a data store whose its stored values expires after specific elapsed time since its creation or last access.

Directories

Path Synopsis
Package memstore provides in-memory data store implementation.
Package memstore provides in-memory data store implementation.
Package mongostore provides MongoDB-backed data store implementation.
Package mongostore provides MongoDB-backed data store implementation.

Jump to

Keyboard shortcuts

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