From aa7f52c16926d76a095e44e0fa4b4f8e2e1728e3 Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Fri, 22 Jun 2012 03:50:10 +0100 Subject: [PATCH] Be clearer about the defaults, <80 width for the janitor comment, and remove 'default cleanup interval' -- there can be only one --- README | 10 +++++----- cache.go | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README b/README index 3e99d04..a040f4e 100644 --- a/README +++ b/README @@ -92,11 +92,11 @@ foo.Println(foo.Num) == Reference func New(de, ci time.Duration) *Cache - Returns a new cache with a given default expiration duration and default - cleanup interval. If the expiration duration is less than 1, the items in - the cache never expire and must be deleted manually. If the cleanup interval - is less than one, expired items are not deleted from the cache before their - next lookup or before calling DeleteExpired. + Returns a new cache with a given default expiration duration and cleanup + interval. If the expiration duration is less than 1, the items in the cache + never expire (by default), and must be deleted manually. If the cleanup + interval is less than one, expired items are not deleted from the cache + before their next lookup or before calling DeleteExpired. func (c *Cache) Set(k string, x interface{}, d time.Duration) Adds an item to the cache, replacing any existing item. If the duration is 0, diff --git a/cache.go b/cache.go index 4f21457..9fa35cc 100644 --- a/cache.go +++ b/cache.go @@ -284,11 +284,11 @@ func stopJanitor(c *Cache) { c.janitor.Stop() } -// Returns a new cache with a given default expiration duration and default cleanup -// interval. If the expiration duration is less than 1, the items in the cache never -// expire and must be deleted manually. If the cleanup interval is less than one, -// expired items are not deleted from the cache before their next lookup or before -// calling DeleteExpired. +// Returns a new cache with a given default expiration duration and cleanup +// interval. If the expiration duration is less than 1, the items in the cache +// never expire (by default), and must be deleted manually. If the cleanup +// interval is less than one, expired items are not deleted from the cache +// before their next lookup or before calling DeleteExpired. func New(de, ci time.Duration) *Cache { if de == 0 { de = -1 @@ -305,10 +305,11 @@ func New(de, ci time.Duration) *Cache { c.janitor = j go j.Run(c) } - // This trick ensures that the janitor goroutine (which--granted it was enabled--is - // running DeleteExpired on c forever) does not keep the returned C object from being - // garbage collected. When it is garbage collected, the finalizer stops the janitor - // goroutine, after which c can be collected. + // This trick ensures that the janitor goroutine (which--granted it + // was enabled--is running DeleteExpired on c forever) does not keep + // the returned C object from being garbage collected. When it is + // garbage collected, the finalizer stops the janitor goroutine, after + // which c can be collected. C := &Cache{c} if ci > 0 { runtime.SetFinalizer(C, stopJanitor)