fcache

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package fcache provides named cache for functions results

supported functions are:

  • Output for OutPutters: Output() ([]byte, error)

cache backend is filesystem directory, and functions are protected by a Lock/Unlock lock := func(name string) Locker

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear added in v1.0.3

func Clear(sig string, dir string, lockDuration time.Duration, lockP func(name string) Locker) error

func Output

func Output(o Outputter, sig string, dir string, lockDuration time.Duration, lockP func(name string) Locker) (out []byte, err error)

Output function returns previous o.Output() results named 'sig' from 'cacheDir', if not found in cache a new value is computed, and cache is updated.

A lock object associated with 'sig' (created by function 'lockP') is used,

When lock error:

Returns o.Output() (no update cache).

When locked:

returns found cache entry associated with 'sig' from 'cacheDir'.
If entry is not present, it runs 'o.Output()'.
  In case of error during o.Output(), the error is returned and cache is not updated,
  else cache associated with 'sig' is updated and new cached value is returned.

dir is created if absent, lockDuration is the maximum duration to wait for lock step.

func Purge

func Purge(cacheDir string) (err error)

Purge cache backend directory 'cacheDir'

Types

type Locker

type Locker interface {
	Lock(time.Duration, string) (err error)
	UnLock() (err error)
}

type Outputter

type Outputter interface {
	Output() ([]byte, error)
}

Jump to

Keyboard shortcuts

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