cache

package module
v1.0.1-0...-cba1e01 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2019 License: MIT Imports: 2 Imported by: 0

README

cache Build Status GoDoc Go Report Card

Go package for dealing with caching. Maybe not so fast.

Requires Go 1.9+ since the package is using type aliases.

Installation

$ go get -u github.com/frozzare/go-cache

Stores

  • Memory
  • Redis
  • Bolt

More cache stores can be implemented by using the provided store interface.

Example

package main

import (
	"log"

	"github.com/frozzare/go-cache"
	"github.com/frozzare/go-cache/store/redis"
)

func main() {
	c := cache.New(redis.NewStore(&redis.Options{
		Addr: "localhost:6379",
	}))

	if err := c.Set("name", "go"); err != nil {
		log.Fatal(err)
	}

	v, err := c.Get("name")
	if err != nil {
		log.Fatal(err)
	}

	log.Println(v)
}

License

MIT © Fredrik Forsmo

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 the cache struct.

func New

func New(store store.Store) *Cache

New with the given options.

func (*Cache) Flush

func (c *Cache) Flush() error

Flush remove all items from the cache.

func (*Cache) Get

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

Get will retrive a item from the cache.

func (*Cache) Remove

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

Remove will remove a item from the cache.

func (*Cache) Result

func (c *Cache) Result(key string, v interface{}) error

Result will retrieve a item from the cache and stores the result in the value pointed to by v.

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}, expiration ...time.Duration) error

Set will store a item in the cache.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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