csvcache

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2017 License: MIT Imports: 9 Imported by: 2

README

CSV Cache

GoDoc Build Status Code Coverage Go Report Card

Cache data in CSV files in Golang.

Installation

Simple install the package to your $GOPATH with the go tool:

$ go get -u github.com/rvflash/csv-cache

Usage

This small library allows you to manage CSV data with a time to live, based on the last modified time.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotStored  = errors.New("item not stored")
	ErrCacheMiss  = errors.New("cache miss")
	ErrInvalidKey = errors.New("invalid key")
)

Error messages.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a wrapper around os.File providing simple file caching.

func New

func New(dir string, expire time.Duration) *Cache

New returns an instance of Cache.

func (*Cache) Add

func (c *Cache) Add(d *Item) error

Add writes the given item, if no value already exists for its key. ErrNotStored is returned if that condition is not met.

func (*Cache) Delete

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

Delete deletes the item with the provided key. ErrCacheMiss is returned if the item didn't already exist in the cache.

func (*Cache) DeleteAll

func (c *Cache) DeleteAll() error

DeleteAll deletes all items in the cache.

func (*Cache) FlushAll

func (c *Cache) FlushAll() error

FlushAll flushes all expired items in the cache.

func (*Cache) Get

func (c *Cache) Get(key string) ([][]string, error)

Get gets the item for the given key. ErrCacheMiss is returned for a cache miss.

func (*Cache) Replace

func (c *Cache) Replace(d *Item) error

Replace writes the given item, but only if the server has already its key. ErrNotStored is returned if that condition is not met.

func (*Cache) Set

func (c *Cache) Set(d *Item) error

Set writes the given item, unconditionally. ErrNotStored is returned if we can not create a file into this directory.

type Item

type Item struct {
	Key   string
	Value [][]string
}

Item is an item to be got or stored in the cache directory.

Jump to

Keyboard shortcuts

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