cache: github.com/go-macaron/cache Index | Files | Directories

package cache

import "github.com/go-macaron/cache"

Package cache is a middleware that provides the cache management of Macaron.

Index

Package Files

cache.go file.go memory.go utils.go

func Cacher Uses

func Cacher(options ...Options) macaron.Handler

Cacher is a middleware that maps a cache.Cache service into the Macaron handler chain. An single variadic cache.Options struct can be optionally provided to configure.

func DecodeGob Uses

func DecodeGob(data []byte, out *Item) error

func Decr Uses

func Decr(val interface{}) (interface{}, error)

func EncodeGob Uses

func EncodeGob(item *Item) ([]byte, error)

func Incr Uses

func Incr(val interface{}) (interface{}, error)

func Register Uses

func Register(name string, adapter Cache)

Register registers a adapter.

func Version Uses

func Version() string

type Cache Uses

type Cache interface {
    // Put puts value into cache with key and expire time.
    Put(key string, val interface{}, timeout int64) error
    // Get gets cached value by given key.
    Get(key string) interface{}
    // Delete deletes cached value by given key.
    Delete(key string) error
    // Incr increases cached int-type value by given key as a counter.
    Incr(key string) error
    // Decr decreases cached int-type value by given key as a counter.
    Decr(key string) error
    // IsExist returns true if cached value exists.
    IsExist(key string) bool
    // Flush deletes all cached data.
    Flush() error
    // StartAndGC starts GC routine based on config string settings.
    StartAndGC(opt Options) error
}

Cache is the interface that operates the cache data.

func NewCacher Uses

func NewCacher(name string, opt Options) (Cache, error)

NewCacher creates and returns a new cacher by given adapter name and configuration. It panics when given adapter isn't registered and starts GC automatically.

type FileCacher Uses

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

FileCacher represents a file cache adapter implementation.

func NewFileCacher Uses

func NewFileCacher() *FileCacher

NewFileCacher creates and returns a new file cacher.

func (*FileCacher) Decr Uses

func (c *FileCacher) Decr(key string) error

Decrease cached int value.

func (*FileCacher) Delete Uses

func (c *FileCacher) Delete(key string) error

Delete deletes cached value by given key.

func (*FileCacher) Flush Uses

func (c *FileCacher) Flush() error

Flush deletes all cached data.

func (*FileCacher) Get Uses

func (c *FileCacher) Get(key string) interface{}

Get gets cached value by given key.

func (*FileCacher) Incr Uses

func (c *FileCacher) Incr(key string) error

Incr increases cached int-type value by given key as a counter.

func (*FileCacher) IsExist Uses

func (c *FileCacher) IsExist(key string) bool

IsExist returns true if cached value exists.

func (*FileCacher) Put Uses

func (c *FileCacher) Put(key string, val interface{}, expire int64) error

Put puts value into cache with key and expire time. If expired is 0, it will not be deleted by GC.

func (*FileCacher) StartAndGC Uses

func (c *FileCacher) StartAndGC(opt Options) error

StartAndGC starts GC routine based on config string settings.

type Item Uses

type Item struct {
    Val     interface{}
    Created int64
    Expire  int64
}

Item represents a cache item.

type MemoryCacher Uses

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

MemoryCacher represents a memory cache adapter implementation.

func NewMemoryCacher Uses

func NewMemoryCacher() *MemoryCacher

NewMemoryCacher creates and returns a new memory cacher.

func (*MemoryCacher) Decr Uses

func (c *MemoryCacher) Decr(key string) (err error)

Decr decreases cached int-type value by given key as a counter.

func (*MemoryCacher) Delete Uses

func (c *MemoryCacher) Delete(key string) error

Delete deletes cached value by given key.

func (*MemoryCacher) Flush Uses

func (c *MemoryCacher) Flush() error

Flush deletes all cached data.

func (*MemoryCacher) Get Uses

func (c *MemoryCacher) Get(key string) interface{}

Get gets cached value by given key.

func (*MemoryCacher) Incr Uses

func (c *MemoryCacher) Incr(key string) (err error)

Incr increases cached int-type value by given key as a counter.

func (*MemoryCacher) IsExist Uses

func (c *MemoryCacher) IsExist(key string) bool

IsExist returns true if cached value exists.

func (*MemoryCacher) Put Uses

func (c *MemoryCacher) Put(key string, val interface{}, expire int64) error

Put puts value into cache with key and expire time. If expired is 0, it will be deleted by next GC operation.

func (*MemoryCacher) StartAndGC Uses

func (c *MemoryCacher) StartAndGC(opt Options) error

StartAndGC starts GC routine based on config string settings.

type MemoryItem Uses

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

MemoryItem represents a memory cache item.

type Options Uses

type Options struct {
    // Name of adapter. Default is "memory".
    Adapter string
    // Adapter configuration, it's corresponding to adapter.
    AdapterConfig string
    // GC interval time in seconds. Default is 60.
    Interval int
    // Occupy entire database. Default is false.
    OccupyMode bool
    // Configuration section name. Default is "cache".
    Section string
}

Options represents a struct for specifying configuration options for the cache middleware.

Directories

PathSynopsis
ledis
memcache
mysql
nodb
postgres
redis

Package cache imports 14 packages (graph) and is imported by 162 packages. Updated 2019-08-21. Refresh now. Tools for package owners.