data

package
v0.0.0-...-f4bd7b1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2015 License: Apache-2.0, Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package data implements in memory caching methods for data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// Mutex is used for handling the concurrent
	// read/write requests for cache
	sync.Mutex

	// OnEvicted - callback function for eviction
	OnEvicted func(a ...interface{})
	// contains filtered or unexported fields
}

Cache holds the required variables to compose an in memory cache system which also provides expiring key mechanism and also maxSize

func NewCache

func NewCache(maxSize uint64) *Cache

NewCache creates an inmemory cache

maxSize is used for expiring objects before we run out of memory expiration is used for expiration of a key from cache

func (*Cache) Append

func (r *Cache) Append(key interface{}, value []byte) bool

Append will append new data to an existing key, if key doesn't exist it behaves like Set()

func (*Cache) Delete

func (r *Cache) Delete(key interface{})

Delete deletes a given key if exists

func (*Cache) Get

func (r *Cache) Get(key interface{}) ([]byte, bool)

Get returns a value of a given key if it exists

func (*Cache) Len

func (r *Cache) Len(key interface{}) int

Len returns length of the value of a given key, returns zero if key doesn't exist

func (*Cache) Set

func (r *Cache) Set(key interface{}, value []byte) bool

Set will persist a value to the cache

func (*Cache) SetMaxSize

func (r *Cache) SetMaxSize(maxSize uint64)

SetMaxSize set a new max size

func (*Cache) Stats

func (r *Cache) Stats() Stats

Stats get current cache statistics

type Stats

type Stats struct {
	Bytes   uint64
	Items   int
	Evicted int
}

Stats current cache statistics

Jump to

Keyboard shortcuts

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