package
0.21.1
Repository: https://github.com/e154/smart-home.git
Documentation: pkg.go.dev

# README

cache

cache is a Go cache manager. It can use many cache adapters. The repo is inspired by database/sql .

How to install?

go get github.com/astaxie/beego/cache

What adapters are supported?

As of now this cache support memory, Memcache and Redis.

How to use it?

First you must import it

import (
	"github.com/astaxie/beego/cache"
)

Then init a Cache (example with memory adapter)

bm, err := cache.NewCache("memory", `{"interval":60}`)	

Use it like this:

bm.Put("astaxie", 1, 10 * time.Second)
bm.Get("astaxie")
bm.IsExist("astaxie")
bm.Delete("astaxie")

Memory adapter

Configure memory adapter like this:

{"interval":60}

interval means the gc time. The cache will check at each time interval, whether item has expired.

Memcache adapter

Memcache adapter use the gomemcache client.

Configure like this:

{"conn":"127.0.0.1:11211"}

Redis adapter

Redis adapter use the redigo client.

Configure like this:

{"conn":":6039"}

# Functions

FileGetContents Reads bytes from a file.
FilePutContents puts bytes into a file.
GetBool converts interface to bool.
GetFloat64 converts interface to float64.
GetInt converts interface to int.
GetInt64 converts interface to int64.
GetString converts interface to string.
GobDecode Gob decodes a file cache item.
GobEncode Gob encodes a file cache item.
NewCache creates a new cache driver by adapter name and config string.
NewFileCache creates a new file cache with no config.
NewMemoryCache returns a new MemoryCache.
Register makes a cache adapter available by the adapter name.

# Variables

1 minute.
cache file deep level if auto generated cache files.
cache expire time, default is no expire forever.
cache file suffix.
cache directory.

# Structs

FileCache is cache adapter for file storage.
FileCacheItem is basic unit of file cache adapter which contains data and expire time.
MemoryCache is a memory cache adapter.
MemoryItem stores memory cache item.

# Interfaces

Cache interface contains all behaviors for cache adapter.

# Type aliases

Instance is a function create a new Cache Instance.