Documentation
¶
Index ¶
- Constants
- Variables
- func Initialise(v bool, o *Options) error
- func Terminate()
- type Bucket
- func (c *Bucket) Add(k string, vn interface{}, t time.Duration, pers bool) (string, bool)
- func (c *Bucket) Close(keep bool)
- func (c *Bucket) Compact()
- func (c *Bucket) Delete(k string)
- func (c *Bucket) DeleteExpired()
- func (c *Bucket) Flush()
- func (c *Bucket) FunctionUpdate(k string, f updateFunc, t time.Duration, pers bool) (string, string, bool)
- func (c *Bucket) Get(k string) (string, bool)
- func (c *Bucket) GetWithExpiration(k string) (string, time.Time, bool)
- func (c *Bucket) ItemCount() int
- func (c *Bucket) Items() (rt map[string]string)
- func (c *Bucket) OnEvicted(f func(string, interface{}))
- func (c *Bucket) Replace(k string, vn interface{}, t time.Duration, pers bool)
- func (c *Bucket) Set(k string, vn interface{}, t time.Duration, pers bool)
- func (c *Bucket) Update(k string, vn interface{}, t time.Duration, pers bool)
- type FileData
- type Item
- type Options
Constants ¶
const ( // To be used to set key/pair without expiration date NoExpiration time.Duration = -1 // To be used to set key/pair with expiration date as from the bucket declaration DefaultExpiration time.Duration = 0 )
Variables ¶
var (
IllegalParameter = errors.New("illegal parameter given")
)
Functions ¶
func Initialise ¶
Initialise prepare the cache for use. It accept two parameters:
v : set to true for verbose (useful for development purposes) o : are the database options (see inm types.go for further details)
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
func NewBucket ¶
NewBucket create a new bucket in the cache.
If a rec file or a data file are present and are not older than time.Now() - maxage, they will be loaded in the cache
func (*Bucket) Add ¶
Add add a new key/value pair only if it does not already
It marks the key/value pair persistent if pers is true.
func (*Bucket) Close ¶
Close closes a bucket storing values in the recovery data
if keep is false the working data file will be deleted
func (*Bucket) Compact ¶
func (c *Bucket) Compact()
Compact initiate a compation request of the working files.
Please note that all values will be used and any previously indicated persistence flag will be ignored.
func (*Bucket) DeleteExpired ¶
func (c *Bucket) DeleteExpired()
DeleteExpired deletes all expired items from the bucketInternal.
func (*Bucket) FunctionUpdate ¶
func (c *Bucket) FunctionUpdate(k string, f updateFunc, t time.Duration, pers bool) (string, string, bool)
FunctionUpdate updates the new key/value with a custom function of type
func(k, v string) (string, string). The function is given the actual key/value pair is present and key/"" otherwise and it expects a new key/value pair. if the function modofies the key, the old key/pair is deleted. It marks the key/value pair persistent if pers is true.
func (*Bucket) Get ¶
Get read the value associated to the key k
It also returns false if the key has not value associated to it
func (*Bucket) GetWithExpiration ¶
GetWithExpiration performs the same operation as Get but it also returns the
value expiration time
func (*Bucket) ItemCount ¶
ItemCount returns the number of items in the bucket. This may include items that have
expired, but have not yet been cleaned up.
func (*Bucket) OnEvicted ¶
OnEvicted sets an (optional) function that is called with the key and value when an
item is evicted from the bucketInternal. (Including when it is deleted manually, but not when it is overwritten.) Set to nil to disable.
func (*Bucket) Replace ¶
Replace replaces an existing key/value pair only it already existing.
It marks the key/value pair persistent if pers is true.
type Options ¶
type Options struct { ExpirationTime int // Expiration time is seconds IntervalCompacting int // Cache working files compacting interval in seconds (values smaller than 60s will be defaulted to 60s) InternalBuffering int // Buffering length to decouple the in-memory cache from the disk processes. Bigger numbers improve cache speed at expenses of system crash resistance LoadDelayMs int // Regulates the start-up delay. Smaller numbers improves start-up time at costs of possible loss of persistence MaximumAge int64 // Maximum age (in s) of a back-up file (.rec) or working file (.data) for it to be used to initialise the cache WorkingFolder string // folder for working files (.data). File contain the entire cache in a readable. Altering the files only affects the initial cache load not its operation RecoveryFolder string // folder for back-up files (.rec) }
Default options are
ExpirationTime: 0, IntervalCompacting: 1440 * 60, InternalBuffering: 10, LoadDelayMs: 10, MaximumAge: 5 * 60,