caching

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2014 License: Apache-2.0 Imports: 3 Imported by: 1

README

#Golang Caching Package

The package providers a scalable caching component.

##Container

The container represents an adapter for caching manager/service.

###Available 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).

  • Memcache Container: the adapter for memcached.

##Dependency

The dependency represents an expiration policy.

###Available Dependencies

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

##Examples

###Example: File Configuration Caching

    import (
        "github.com/landjur/go-caching"
        "github.com/landjur/go-caching/container/memory"
        _ "github.com/landjur/go-caching/container/memory/arc"
        _ "github.com/landjur/go-caching/dependency/file"
    )

    container := memory.ARC.New(1000)   // local memory container (ARC), capacity: 1000 (NOTE: not safe for concurrent access)
    cache := caching.New(container)
    cache.Set("key", "value")           // memory container always returns nil error
    cache.Set("configuration-key", "settings", file.New(path)) // dependency by configuration file

###Example: Multi-Level Caching

    import (
        "github.com/landjur/go-caching"
        "github.com/landjur/go-caching/container/concurrent"
        "github.com/landjur/go-caching/container/memcache"
        "github.com/landjur/go-caching/container/memory"
        _ "github.com/landjur/go-caching/container/memory/arc"
        "github.com/landjur/go-caching/container/multilevel"
    )

    level1 := concurrent.New(memory.ARC.New(1000)) // local memory container (ARC), capacity: 1000, safe for concurrent access
    level2 := memcache.New("192.168.100.101:11211")
    container := multilevel.New(level1, level2) // local memory as level 1, memcached as level 2
    cache := caching.New(container)
    err := cache.Set("key", "value")    // memcached may return error
    if err != nil {
        // handle error
    }

##COPYRIGHT & LICENSE

Copyright 2014 Landjur, Inc. Code released under the Apache License, Version 2.0.

Documentation

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.

func New added in v1.0.0

func New(container container.Container) *Cache

New returns a new cache.

func (Cache) Clear

func (this Cache) Clear() error

Clear removes all items.

func (*Cache) Get

func (this *Cache) Get(key string) (interface{}, error)

Get returns the item by given key.

func (Cache) Remove

func (this Cache) Remove(key string) error

Remove removes the item by given key.

func (Cache) Set

func (this Cache) Set(key string, value interface{}, dependencies ...dependency.Dependency) error

Set sets(inserts/updates) item.

Jump to

Keyboard shortcuts

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