cache

package module
v0.0.0-...-a2f508c Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: MIT Imports: 4 Imported by: 0

README

cache

Go

TODO

  • Memory
  • Redis
  • Memcached
  • FileSystem
  • More Function ……

Installation

go get github.com/go-packagist/cache

Usage

package main

import (
	"fmt"
	"github.com/go-packagist/cache"
	"time"
)

func main() {
	cache.Configure("memory", cache.NewMemoryStore())
	cache.Configure("memory2", cache.NewMemoryStore())

	cache.Store("memory").Put("a", "2", time.Second*1)
	cache.Store("memory2").Put("aa", "2", time.Second*1)

	fmt.Println(cache.Store("memory").Get("a"))
	fmt.Println(cache.Store("memory2").Get("aa"))
	fmt.Println(cache.Store("memory2").Get("a"))

	time.Sleep(time.Second * 2)

	fmt.Println(cache.Store("memory").Get("a"))
	fmt.Println(cache.Store("memory2").Get("aa"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(name string, store Cache)

Types

type Cache

type Cache interface {
	Get(key string) *Result
	Put(key string, value interface{}, expire time.Duration) error
	Has(key string) bool
	Remember(key string, fc func() interface{}, expire time.Duration) *Result
	GC() error
}

func NewMemoryStore

func NewMemoryStore() Cache

func NewRedisStore

func NewRedisStore(client *redis.Client) Cache

func Store

func Store(name string) Cache

type MarshalFunc

type MarshalFunc func(interface{}) ([]byte, error)

type Result

type Result struct {
	Val interface{}
	Err error
}

func (*Result) Error

func (r *Result) Error() error

func (*Result) IsError

func (r *Result) IsError() bool

func (*Result) ValOrNil

func (r *Result) ValOrNil() interface{}

func (*Result) Value

func (r *Result) Value() interface{}

type UnmarshalFunc

type UnmarshalFunc func([]byte, interface{}) error

Jump to

Keyboard shortcuts

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