honoka

package module
v0.0.0-...-2ba248c Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2015 License: MIT Imports: 11 Imported by: 2

README

仄 (honoka)

file cache library in Golang.

Installation

Standard go get:

$ go get -u github.com/YusukeKomatsu/honoka

Usage & Example

For usage and examples see the Godoc.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version            = "0.0.1"
	BucketFileNotFound = errors.New("Not found specified bucket file")
	IndexFileNotFound  = errors.New("Not found specified index file")
	CacheIsExpired     = errors.New("specified cache is expired")
)

Functions

This section is empty.

Types

type CleanResult

type CleanResult struct {
	// The bucket name that saved cache data.
	Bucket string

	// Error when delete the specified bucket.
	Error error
}

The structure is used when use clean method.

type Client

type Client struct {
	// Cache Index list
	Indexer IndexList
}

Cache client

func New

func New() (*Client, error)

New is a function for making a new cache

func (*Client) Clean

func (c *Client) Clean() ([]CleanResult, error)

Clean is used to delete no-indexed bucket. Example:

cli, err := honoka.New()
result, err := cli.Clean()

func (*Client) Delete

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

Delete is used to delete a cache by specified key.

Example:

cli, err := honoka.New()
err = cli.Delete("foobar")

func (*Client) Expire

func (c *Client) Expire(key string) bool

Expire is a predicate which determines if the cache should be updated.

Example:

cli, err := honoka.New()
expired := cli.Expire("foobar")

func (*Client) Get

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

Get is used to retrieve a cache by specified key.

Example:

cli, err := honoka.New()
var output interface{}
cli.Get("foobar", &output)
// OR
result, err := cli.Get("foobar", &output)

func (*Client) GetJson

func (c *Client) GetJson(key string) ([]byte, error)

Get is used to retrieve a cache by specified key. Return value is JSON string Example:

cli, err := honoka.New()
result, err := cli.GetJson("foobar")

func (*Client) List

func (c *Client) List() ([]Index, error)

List is used to retrive cache indexes.

Example:

cli, err := honoka.New()
list, err := cli.List()

func (*Client) Outdated

func (c *Client) Outdated() ([]string, error)

Outdated is used to retrive no-indexed bucket.

Example:

cli, err := honoka.New()
list, err := cli.Outdated()

func (*Client) Set

func (c *Client) Set(key string, val interface{}, expire int64) error

Get is used to create a cache if specified key has not used yet.

Example:

cli, err := honoka.New()
err := cli.Set("foobar", "fizzbizz", 100)

func (*Client) Update

func (c *Client) Update(key string, updater UpdateFunc, expire int64, output interface{}) (interface{}, error)

Update calls the cache update function on the cached data. Get is used to retrieve a cache by specified key.

Example:

cli, err := honoka.New()
var output interface{}
f := func() { return "fizzbizz" }
cli.Update("foobar", f, 100, &output)
// OR
result, err := cli.Get("foobar", f, 100, &output)

func (*Client) UpdateJson

func (c *Client) UpdateJson(key string, updater UpdateFunc, expire int64) ([]byte, error)

Update calls the cache update function on the cached data. Return value is JSON string.

Example:

cli, err := honoka.New()
f := func() { return "fizzbizz" }
result, err := cli.UpdateJson("foobar", f, 100)

type Index

type Index struct {
	// The index key.
	Key string

	// The bucket name that saved cache data.
	Bucket string

	// The maximum elapsed time since the last file update.
	Expiration int64
}

Cache index

type IndexList

type IndexList map[string]Index

Cache index list

type UpdateFunc

type UpdateFunc func() (interface{}, error)

Directories

Path Synopsis
client

Jump to

Keyboard shortcuts

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