scache

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2015 License: MIT Imports: 6 Imported by: 0

README

scache

A simple concurrent friendly cache

// a cache that'll hold 1000 users, users expire 1 minute after being inserted
userCache := scacne.New(1000, time.Minute)

// GET
u := userCache.Get("leto")
if u == nil {
  return nil
}
user := u.(*User)

// SET
userCache.Set("leto", user)

Documentation

Overview

a simple cache

Index

Constants

This section is empty.

Variables

View Source
var (
	BUCKET_COUNT = 16 //must be a power of 2

)

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Bucket) Get

func (b *Bucket) Get(key string) *Item

func (*Bucket) Remove

func (b *Bucket) Remove(key string) bool

func (*Bucket) Set

func (b *Bucket) Set(key string, item *Item) bool

type Item

type Item struct {
	Expires time.Time
	Value   interface{}
}

type Scache

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

func New

func New(max int32, ttl time.Duration) *Scache

func (*Scache) Fetch

func (sc *Scache) Fetch(key string, miss func(key string) (interface{}, error)) (interface{}, error)

func (*Scache) Get

func (sc *Scache) Get(key string) interface{}

func (*Scache) Set

func (sc *Scache) Set(key string, value interface{})

Jump to

Keyboard shortcuts

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