caching

package module
v1.0.1-0...-4a73120 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

README

caching

Package caching providers a scalable cache component.

Container

The container represents an adapter for cache manager/service.

Builtin Containers
  • Concurrent Container: wrapping a container for concurrent access.
  • Multi-Level Container: wrapping the containers into a single container.
  • Memory Containers: local memory containers (not safe for concurrent access).
    • FIFO Container: replacement algorithm using FIFO (first in first out).
    • LFU Container: replacement algorithm using LFU (least frequently used).
    • LRU Container: replacement algorithm using LRU (least recently used).
    • MRU Container: replacement algorithm using MRU (most recently used).
    • ARC Container: replacement algorithm using ARC (adaptive/adjustable replacement cache).

Dependency

The dependency represents an external expiration policy.

Builtin Dependencies
  • File Dependency: it's useful for caching configuration file.

Documentation

Overview

Package caching providers a scalable cache component.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache represents a cache manager.

func MustNewCache

func MustNewCache(container Container) *Cache

MustNewCache is like as NewCache but panic if container is nil.

func NewCache

func NewCache(container Container) (*Cache, error)

NewCache returns a new cache.

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all items from cache.

func (*Cache) Get

func (c *Cache) Get(key string) (*Item, error)

Get returns the cache item by given key. It returns nil if cache item has expired or not found.

func (*Cache) Put

func (c *Cache) Put(item *Item) error

Put saves the cache item.

func (*Cache) Remove

func (c *Cache) Remove(key string) error

Remove removes the cache item by given key.

func (*Cache) SetContainer

func (c *Cache) SetContainer(v Container)

SetContainer sets the container for cache.

type Container

type Container interface {
	// Clear removes all items.
	Clear() error

	// Remove removes the item by given key.
	Remove(key string) error

	// Put inserts/updates the item.
	Put(item *Item) error

	// Get returns the value by given key.
	Get(key string) (*Item, error)
}

Container represents a cache container.

type Dependency

type Dependency interface {
	// HasChanged reports whehter dependency has changed.
	HasChanged() bool
}

Dependency represents an external cache dependency.

type Item

type Item struct {
	Key                     string
	Value                   interface{}
	CreatedAt               time.Time
	AccessedAt              time.Time
	AbsoluteExpirationTime  time.Time
	SlidingExpirationPeriod time.Duration
	Dependencies            []Dependency
}

Item represents a cache item.

func MustNewItem

func MustNewItem(key string, value interface{}) *Item

MustNewItem is like as NewItem but panic if key is empty.

func NewItem

func NewItem(key string, value interface{}) (*Item, error)

NewItem returns a new item.

func (*Item) HasExpired

func (i *Item) HasExpired() bool

HasExpired reports whether the item has expired.

func (*Item) Marshal

func (i *Item) Marshal() ([]byte, error)

Marshal marshals the item to byte data by gob.

func (*Item) SetAbsoluteExpiration

func (i *Item) SetAbsoluteExpiration(Absolute time.Time)

SetAbsoluteExpiration sets the Absolute expiration for item.

func (*Item) SetDependencies

func (i *Item) SetDependencies(Dependencies ...Dependency)

SetDependencies sets the Dependencies for item.

func (*Item) SetSlidingExpiration

func (i *Item) SetSlidingExpiration(Sliding time.Duration)

SetSlidingExpiration sets the Sliding expiration for item.

func (*Item) Unmarshal

func (i *Item) Unmarshal(data []byte) error

Unmarshal unmarshals the item from byte data by gob.

Directories

Path Synopsis
container
concurrent
Package concurrent providers a cache container wrapper for safe concurrent access.
Package concurrent providers a cache container wrapper for safe concurrent access.
memory
Package memory providers in-memory cache containers.
Package memory providers in-memory cache containers.
memory/arc
Package arc providers an in-memory cache container using ARC (adaptive/adjustable replacement cache) arithmetic.
Package arc providers an in-memory cache container using ARC (adaptive/adjustable replacement cache) arithmetic.
memory/fifo
Package fifo providers an in-memory cache container using FIFO (first in first out) arithmetic.
Package fifo providers an in-memory cache container using FIFO (first in first out) arithmetic.
memory/lfu
Package lfu providers an in-memory cache container using LFU (least frequently used) arithmetic.
Package lfu providers an in-memory cache container using LFU (least frequently used) arithmetic.
memory/lru
Package lru providers an in-memory cache Container using LRU (least recently used) arithmetic.
Package lru providers an in-memory cache Container using LRU (least recently used) arithmetic.
memory/mru
Package mru providers an in-memory cache Container using MRU (most recently used) arithmetic.
Package mru providers an in-memory cache Container using MRU (most recently used) arithmetic.
multilevel
Package multilevel providers a cache container wrapper for wrapping multi-level containers.
Package multilevel providers a cache container wrapper for wrapping multi-level containers.
dependency
file
Package file providers a file caching dependency.
Package file providers a file caching dependency.

Jump to

Keyboard shortcuts

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