March 2019
Intermediate to advanced
336 pages
9h 9m
English
The SetValue method of the Cache class takes cacheKey, cacheValue, and timeToLive parameters. The Lock method on the mutex object of the cache is invoked, and the Unlock method is deferred. A new CacheObject is created with cacheValue and TimeToLive as properties. The created cacheObject is set as a value to map objects with the cacheKey key. This is shown in the following code:
//SetValue methodfunc (cache Cache) SetValue(cacheKey string, cacheValue string, timeToLive time.Duration) { cache.mutex.Lock() defer cache.mutex.Unlock() cache.objects[cacheKey] = CacheObject{ Value: cacheValue, TimeToLive: time.Now().Add(timeToLive).UnixNano(), }}
We'll implement the methods we just took a look at in the main method in the next ...
Read now
Unlock full access