objcache

package
v0.0.0-...-ecc7113 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

README

PACKAGE DOCUMENTATION

package objcache
    import "github.com/minio/minio/pkg/objcache"

    Package objcache implements in memory caching methods.

CONSTANTS

    const (
    	// NoExpiry represents caches to be permanent and can only be deleted.
    	NoExpiry = time.Duration(0)

    	// DefaultExpiry represents three days time duration when individual entries will be expired.
    	DefaultExpiry = time.Duration(3 * 24 * time.Hour)
    )

VARIABLES

var ErrCacheFull = errors.New("Not enough space in cache")
    ErrCacheFull - cache is full.

var ErrKeyNotFoundInCache = errors.New("Key not found in cache")
    ErrKeyNotFoundInCache - key not found in cache.

TYPES

type Cache struct {

    // OnEviction - callback function for eviction
    OnEviction func(key string)
    // contains filtered or unexported fields
}
    Cache holds the required variables to compose an in memory cache system
    which also provides expiring key mechanism and also maxSize.

func New(maxSize uint64, expiry time.Duration) *Cache
    New - Return a new cache with a given default expiry duration. If the
    expiry duration is less than one (or NoExpiry), the items in the cache
    never expire (by default), and must be deleted manually.

func (c *Cache) Create(key string, size int64) (w io.WriteCloser, err error)
    Create - validates if object size fits with in cache size limit and
    returns a io.WriteCloser to which object contents can be written and
    finally Close()'d. During Close() we checks if the amount of data
    written is equal to the size of the object, in which case it saves the
    contents to object cache.

func (c *Cache) Delete(key string)
    Delete - delete deletes an entry from the cache.

func (c *Cache) DeleteExpired()
    DeleteExpired - deletes all the expired entries from the cache.

func (c *Cache) Open(key string) (io.ReadSeeker, error)
    Open - open the in-memory file, returns an in memory read seeker.
    returns an error ErrNotFoundInCache, if the key does not exist.

func (c *Cache) StopExpiry()
    StopExpiry sends a message to the expiry routine to stop expiring cached
    entries. NOTE: once this is called, cached entries will not be expired
    if the consume has called this.

Documentation

Overview

Package objcache implements in memory caching methods.

Package objcache implements in memory caching methods.

Index

Constants

View Source
const (
	// NoExpiry represents caches to be permanent and can only be deleted.
	NoExpiry = time.Duration(0)

	// DefaultExpiry represents three days time duration when individual entries will be expired.
	DefaultExpiry = time.Duration(3 * 24 * time.Hour)
)

Variables

View Source
var (
	// ErrKeyNotFoundInCache - key not found in cache.
	ErrKeyNotFoundInCache = errors.New("Key not found in cache")

	// ErrCacheFull - cache is full.
	ErrCacheFull = errors.New("Not enough space in cache")

	// ErrExcessData - excess data was attempted to be written on cache.
	ErrExcessData = errors.New("Attempted excess write on cache")
)

Functions

This section is empty.

Types

type Cache

type Cache struct {

	// OnEviction - callback function for eviction
	OnEviction func(key string)
	// contains filtered or unexported fields
}

Cache holds the required variables to compose an in memory cache system which also provides expiring key mechanism and also maxSize.

func New

func New(maxSize uint64, expiry time.Duration) (c *Cache, err error)

New - Return a new cache with a given default expiry duration. If the expiry duration is less than one (or NoExpiry), the items in the cache never expire (by default), and must be deleted manually.

func (*Cache) Create

func (c *Cache) Create(key string, size int64) (w io.WriteCloser, err error)

Create - validates if object size fits with in cache size limit and returns a io.WriteCloser to which object contents can be written and finally Close()'d. During Close() we checks if the amount of data written is equal to the size of the object, in which case it saves the contents to object cache.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete - delete deletes an entry from the cache.

func (*Cache) Open

func (c *Cache) Open(key string, objModTime time.Time) (io.ReaderAt, error)

Open - open the in-memory file, returns an in memory read seeker. returns an error ErrNotFoundInCache, if the key does not exist. Returns ErrKeyNotFoundInCache if entry's lastAccessedTime is older than objModTime.

func (*Cache) StartGC

func (c *Cache) StartGC()

StartGC starts running a routine ticking at expiry interval, on each interval this routine does a sweep across the cache entries and garbage collects all the expired entries.

func (*Cache) StopGC

func (c *Cache) StopGC()

StopGC sends a message to the expiry routine to stop expiring cached entries. NOTE: once this is called, cached entries will not be expired, be careful if you are using this.

Jump to

Keyboard shortcuts

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