Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CollectGarbageTimeout = errors.New("CollectGarbage timed out")
var NotFound = fmt.Errorf("Key-value pair was not found")
Functions ¶
func CollectGarbage ¶
CollectGarbage deletes expired kv entities from the datastore. This function should be called regularly to prevent expired kvs from accumulating in the datastore. Returns the number of entities that were removed from datastore.
If GC.Ttl is reached, returns CollectGarbageTimeout regardless how many entities were expired before then.
func Modify ¶
Modify atomically changes the value of a KV by applying a function to its current value. The bool given to the callback is true if the key exists and hasn't expired, false otherwise.
The callback should return an error if it's unable to modify the value given. That error value becomes Modify's error value.
Put and Modify don't play well together. For any given key, it's best to choose one and use it exclusively for all writes. Find works well for reads in both cases.
Types ¶
type GC ¶
type GC struct { // Ttl describes how much time a single GC operation should be allowed to run. // This can be tuned based on how frequently GC jobs are executed. For // example, if GC runs once per minute, you might set Ttl to 50 seconds. // // Ttl is only a guideline for the GC operation. It might run longer or // shorter than this target. // // Defaults to 50 seconds. Ttl time.Duration // Leeway describes how far past its expiration a KV must be before it's // considered for garbage collection. It should be set high enough that // the probability of a KV being used again is very low. // // Defaults to 24 hours. Leeway time.Duration }
GC defines options for how to perform garbage collection on KV entities.
type KV ¶
type KV struct { Key string `datastore:",noindex"` Value []byte `datastore:",noindex"` Expires time.Time Ttl time.Duration `datastore:"-"` // convenient alternative to Expires }
func (*KV) Decompress ¶
Decompress rewrites the Value field by decompressing it with gzip.