Documentation
¶
Overview ¶
concurrency-safe file-backed element store
- Asynchronous writes (errors reported on next action)
- Optional cache with LRU eviction on either store insertion or store retrieval
To avoid a lot of casting from store.Element on Store#Get, you should probably write a wrapper around this element store for each type you intend to use it for.
Pull requests welcome
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrAlreadyExists = errors.New("element already exists in store") ErrDoesNotExist = errors.New("element not present in store") )
Functions ¶
This section is empty.
Types ¶
type CacheMode ¶
type CacheMode int
Tells the store when to pass an element to the cache
const ( CacheOnGet CacheMode = (1 << 0) CacheOnPut = (1 << 1) )
type Element ¶
type Element interface {
// load an element from a reader
Load(io.Reader) error
// store an element to a writer
Store(io.Writer) error
// must return a file-system safe ID
// the two first letters of ID will be
// used to create directories and the
// complete ID string will be used as
// a file name
ID() ElementID
}
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
cache with LRU eviction policy
func NewLRUCache ¶
create a new cache with room for 'size' elements
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) Get ¶
retrieve an Element either from cache or from disk. If retrieved from cache, the cache Element will be returned. If retrieved from disk, the Element passed to Get will be loaded with the data from disk. Therefor, this function should always be called like:
var el = SomeElement{ID: someID}
ret, err := s.Get(&el)
Click to show internal directories.
Click to hide internal directories.