X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=key_value_cache%2Fkey_value_cache.go;h=9292de57e02a56fd0fc2e0190cc2d5ee0c37c8c8;hb=0b7bb57744ef4be1855155bccd96f6370061c009;hp=e5881b647505edecb20ab2438c7859f86e50da6a;hpb=79dc9f00908f1bc9d46d5c5eeadada11a02b08d1;p=pstop.git diff --git a/key_value_cache/key_value_cache.go b/key_value_cache/key_value_cache.go index e5881b6..9292de5 100644 --- a/key_value_cache/key_value_cache.go +++ b/key_value_cache/key_value_cache.go @@ -1,3 +1,7 @@ +// key_value_cache provides an extremely simple string key to value cache. +// This is used to reduce the number of lookups from MySQL filename +// to the equivalent table or logical name given the conversion +// routines to do this use many regexps and this is quite expensive. package key_value_cache import ( @@ -12,15 +16,14 @@ type KeyValueCache struct { read_requests, served_from_cache, write_requests int } -// create a new KeyValueCache entry +// Create a new KeyValueCache entry. func NewKeyValueCache() KeyValueCache { lib.Logger.Println("KeyValueCache()") - var kvc KeyValueCache - return kvc + return KeyValueCache{} } -// return value if found +// Given a lookup key return the value if found. func (kvc *KeyValueCache) Get(key string) (result string, err error) { lib.Logger.Println("KeyValueCache.Get(", key, ")") if kvc.cache == nil { @@ -43,13 +46,15 @@ func (kvc *KeyValueCache) Get(key string) (result string, err error) { } } -// write to cache and return value +// Write to cache and return the value saved. func (kvc *KeyValueCache) Put(key, value string) string { lib.Logger.Println("KeyValueCache.Put(", key, ",", value, ")") kvc.cache[key] = value return value } +// Provide some staticts on read and write requests and the number +// of requests served from cache. func (kvc *KeyValueCache) Statistics() (int, int, int) { return kvc.read_requests, kvc.served_from_cache, kvc.write_requests }