caches

package
v0.0.0-...-79bd89f Latest Latest
Warning

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

Go to latest
Published: May 16, 2016 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package caches provides LRU cache and Redis cache

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LCache

type LCache struct {
	// MaxEntries is the maximum number of cache entries before
	// an item is evicted. Zero means no limit.
	MaxEntries int
	// contains filtered or unexported fields
}

Cache is an LRU cache. It is not safe for concurrent access. But it is not necessary for project samaritan.

var LRUCache *LCache

func NewLRUCache

func NewLRUCache(maxEntries int) *LCache

New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.

func (*LCache) Add

func (c *LCache) Add(key string, value interface{})

Add adds a value to the cache.

func (*LCache) Get

func (c *LCache) Get(key string) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*LCache) GetOrRedis

func (c *LCache) GetOrRedis(key string) (value interface{})

Get looks up a key's value from the cache. If failed, load from redis.

func (*LCache) Len

func (c *LCache) Len() int

Len returns the number of items in the cache.

func (*LCache) Remove

func (c *LCache) Remove(key string)

Remove removes the provided key from the cache.

func (*LCache) RemoveOldest

func (c *LCache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

type SimpleCache

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

func NewCache

func NewCache() *SimpleCache

NewCache returns initialized SimpleCache

func (*SimpleCache) Delete

func (c *SimpleCache) Delete(key string)

Delete deletes a key immediately

func (*SimpleCache) Get

func (c *SimpleCache) Get(key string) (value string)

Get looks up a key's value from the cache.

func (*SimpleCache) GetSet

func (c *SimpleCache) GetSet(key, newValue string) (value string)

GetSet looks up a key's value from the cache and set a new value.

func (*SimpleCache) Set

func (c *SimpleCache) Set(key string, value interface{}, px time.Duration)

Set adds a value to the cache.

Jump to

Keyboard shortcuts

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