March 2019
Intermediate to advanced
336 pages
9h 9m
English
The GetObject method retrieves the object given the cache key. The GetObject method of the Cache class returns the value of cacheKey. The RLock method on the mutex object of the cache is invoked, and the RUnlock method is deferred before returning the value of cacheKey. If the object has expired, the key value will be an empty string. This is shown in the following code:
//GetObject methodfunc (cache Cache) GetObject(cacheKey string) string { cache.mutex.RLock() defer cache.mutex.RUnlock() var object CacheObject object = cache.objects[cacheKey] if object.IfExpired() { delete(cache.objects, cacheKey) return "" } return object.Value}
Read now
Unlock full access