sm
/
cache
1
0
Fork 0

Be clearer about the defaults, <80 width for the janitor comment, and remove 'default cleanup interval' -- there can be only one

This commit is contained in:
Patrick Mylund Nielsen 2012-06-22 03:50:10 +01:00
parent 8495026156
commit aa7f52c169
2 changed files with 15 additions and 14 deletions

10
README
View File

@ -92,11 +92,11 @@ foo.Println(foo.Num)
== Reference == Reference
func New(de, ci time.Duration) *Cache func New(de, ci time.Duration) *Cache
Returns a new cache with a given default expiration duration and default Returns a new cache with a given default expiration duration and cleanup
cleanup interval. If the expiration duration is less than 1, the items in interval. If the expiration duration is less than 1, the items in the cache
the cache never expire and must be deleted manually. If the cleanup interval never expire (by default), and must be deleted manually. If the cleanup
is less than one, expired items are not deleted from the cache before their interval is less than one, expired items are not deleted from the cache
next lookup or before calling DeleteExpired. before their next lookup or before calling DeleteExpired.
func (c *Cache) Set(k string, x interface{}, d time.Duration) 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, Adds an item to the cache, replacing any existing item. If the duration is 0,

View File

@ -284,11 +284,11 @@ func stopJanitor(c *Cache) {
c.janitor.Stop() c.janitor.Stop()
} }
// Returns a new cache with a given default expiration duration and default cleanup // 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 // interval. If the expiration duration is less than 1, the items in the cache
// expire and must be deleted manually. If the cleanup interval is less than one, // never expire (by default), and must be deleted manually. If the cleanup
// expired items are not deleted from the cache before their next lookup or before // interval is less than one, expired items are not deleted from the cache
// calling DeleteExpired. // before their next lookup or before calling DeleteExpired.
func New(de, ci time.Duration) *Cache { func New(de, ci time.Duration) *Cache {
if de == 0 { if de == 0 {
de = -1 de = -1
@ -305,10 +305,11 @@ func New(de, ci time.Duration) *Cache {
c.janitor = j c.janitor = j
go j.Run(c) go j.Run(c)
} }
// This trick ensures that the janitor goroutine (which--granted it was enabled--is // This trick ensures that the janitor goroutine (which--granted it
// running DeleteExpired on c forever) does not keep the returned C object from being // was enabled--is running DeleteExpired on c forever) does not keep
// garbage collected. When it is garbage collected, the finalizer stops the janitor // the returned C object from being garbage collected. When it is
// goroutine, after which c can be collected. // garbage collected, the finalizer stops the janitor goroutine, after
// which c can be collected.
C := &Cache{c} C := &Cache{c}
if ci > 0 { if ci > 0 {
runtime.SetFinalizer(C, stopJanitor) runtime.SetFinalizer(C, stopJanitor)