xcache

package
v0.25.15 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 1 Imported by: 7

README

GoKit - xcache

Cache kits for Golang development.

Installation

go get -u github.com/likexian/gokit

Importing

import (
    "github.com/likexian/gokit/xcache"
)

Documentation

Visit the docs on GoDoc

Example

Use memory cache
// init memory cache
c := xcache.New(xcache.MemoryCache)

// set gc param, gc every 60s, once clean max 100
c.SetGC(60, 100)

// set key value cache with no expire
c.Set("key", "value", 0)

// set key value cache with ttl, expire after 30s
c.Set("key", "value", 30)

// check key exists
c.Has("key")

// get value
c.Get("key")

// remove key
c.Del("key")

// get multiple once
c.MGet("k1", "k2", "k3")

// do not forget stop the service
c.Close()

License

Copyright 2012-2024 Li Kexian

Licensed under the Apache License 2.0

Donation

If this project is helpful, please share it with friends.

If you want to thank me, you can give me a cup of coffee.

Documentation

Index

Constants

View Source
const (
	MemoryCache = iota
)

Cacher list

Variables

This section is empty.

Functions

func Author

func Author() string

Author returns package author

func License

func License() string

License returns package license

func Version

func Version() string

Version returns package version

Types

type Cachex

type Cachex interface {
	Get(key string) interface{}
	MGet(key ...string) []interface{}
	Set(key string, val interface{}, ttl int64) error
	Has(key string) bool
	Del(key string) error
	Incr(key string) error
	Decr(key string) error
	SetGC(gcInterval, gcMaxOnce int)
	Flush() error
	Close() error
}

Cachex is cache interface

func New

func New(cacher int) Cachex

New returns a new cacher

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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