resourcecache

package
v0.0.0-...-4baaad8 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2012 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package resourecache implements a cache of files on-disk that contain data from in-memory. The purpose is to allow a Go program to serve content, either static content stored with-in the compiled executable or dynamic content generated as required, to a locally running browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

A Cache maintains an on-disk representation of in-memory content, and maintains a list of the files currently being stored. It is also maintains the information necessary to clean up the cache when the data is no longer required.

func New

func New() *Cache

New creates a new temporary directory for storing content, and returns a handle.

func NewWithPath

func NewWithPath(path string) *Cache

New creates a new temporary directory under the supplied path for storing content, and returns a handle.

func (*Cache) Close

func (c *Cache) Close()

Close deletes all of the temporary files created by the Cache, and then removes the temporary directory.

func (*Cache) Item

func (c *Cache) Item(name string, data []byte, transient bool) (string, error)

Item declares a new item to be cached. The three pieces of information required are the name of the item, the data, and whether or not the item is transient. If a cache item with the same name already exists, than a reference to that file will be returned, otherwise a new file is created, and the contents of data is copied to the new file. The third parameter, transient, is used to indicate temporarily valid data. These items can be purged from the Cache with a call to RemoveTransients.

func (*Cache) RemoveTransients

func (c *Cache) RemoveTransients()

RemoveTransients deletes all the files for items marked as transient. Whereas non-transient items cannot be changed for the life of a Cache, transient items can be purged, and then added anew with different contents.

Jump to

Keyboard shortcuts

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