filecache

package module
v0.0.0-...-0062e03 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2014 License: MIT Imports: 8 Imported by: 2

README

Go File Cache

Build Status GoDoc

This package provides easy to use, file system cache functions.

Full documentation is at: godoc.org/github.com/DannyBen/filecache

Install

$ go get github.com/DannyBen/filecache

Usage

Get the cache handler and set a cache directory and the requested cache life, in minutes:

handler := filecache.Handler{"./cache", 60}

Store data in the cache by providing a string key to the Set method and []byte data. The key's md5 checksum will be used as the filename.

data := []byte("Joey doesn't share food")
handler.Set("testkey", data)

Retrieve data from the cache:

r := handler.Get("testkey")
if r == nil {
	fmt.Println("Cache has expired")
} else  {
	fmt.Println(string(r))
}

Documentation

Overview

Package filecache provides simple file system cache

Example
package main

import (
	"fmt"
	"github.com/DannyBen/filecache"
)

func main() {
	// Get a cache handler with default (temp) directory as
	// the cache directory, and a one hour cache life
	handler := filecache.Handler{Life: 1}

	// Data to store in cache
	data := []byte("Joey doesn't share food")

	// Store the data in the cache
	handler.Set("testkey", data)

	// Retrieve the data from the cache
	r := handler.Get("testkey")

	// Show the result
	fmt.Println(string(r))

}
Output:

Joey doesn't share food

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	Dir  string
	Life float64
}

Type Handler holds the cache directory and cache life in minutes

func (Handler) Filename

func (h Handler) Filename(key string) string

Filename returns the full path to the cache file

func (Handler) Get

func (h Handler) Get(key string) []byte

Get returns content from the cache

func (Handler) Set

func (h Handler) Set(key string, data []byte) error

Set saves content to the cache

Jump to

Keyboard shortcuts

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