all repos — captcha @ c5afad979e03412a52e918c08721999ff477cff6

Go package captcha implements generation and verification of image and audio CAPTCHAs.

captcha: remove Collect method.

Garbage collection is an internal detail of a Store, and requiring to
export this method seem to be not very useful.

The default memory store, of course, still has garbage collection, but
it's not the unexported method, called in Set as usual.
Dmitry Chestnykh dmitry@codingrobots.com
Wed, 27 Apr 2011 23:00:06 +0200
commit

c5afad979e03412a52e918c08721999ff477cff6

parent

e136731cce8382da7030529f2db57e507a60d00c

3 files changed, 10 insertions(+), 33 deletions(-)

jump to
M README.mdREADME.md

@@ -91,16 +91,6 @@

Functions --------- -### func Collect - - func Collect() - -Collect deletes expired or used captchas from the internal storage. It is -called automatically by New function every CollectNum generated captchas, -but still exported to enable freeing memory manually if needed. - -Collection is launched in a new goroutine. - ### func New func New(length int) (id string)

@@ -248,18 +238,16 @@

// Get returns stored digits for the captcha id. Clear indicates // whether the captcha must be deleted from the store. Get(id string, clear bool) (digits []byte) - - // Collect deletes expired captchas from the store. For custom stores - // this method is not called automatically, it is only wired to the - // package's Collect function. Custom stores must implement their own - // procedure for calling Collect, for example, in Set method. - Collect() } ``` An object implementing Store interface can be registered with SetCustomStore function to handle storage and retrieval of captcha ids and solutions for them, replacing the default memory store. + +It is the responsibility of an object to delete expired and used captchas +when necessary (for example, the default memory store collects them in Set +method after the certain amount of captchas has been stored.) ### func NewMemoryStore
M captcha.gocaptcha.go

@@ -166,12 +166,3 @@ }

} return Verify(id, ns) } - -// Collect deletes expired or used captchas from the internal storage. It is -// called automatically by New function every CollectNum generated captchas, -// but still exported to enable freeing memory manually if needed. -// -// Collection is launched in a new goroutine. -func Collect() { - go globalStore.Collect() -}
M store.gostore.go

@@ -9,6 +9,10 @@

// An object implementing Store interface can be registered with SetCustomStore // function to handle storage and retrieval of captcha ids and solutions for // them, replacing the default memory store. +// +// It is the responsibility of an object to delete expired and used captchas +// when necessary (for example, the default memory store collects them in Set +// method after the certain amount of captchas has been stored.) type Store interface { // Set sets the digits for the captcha id. Set(id string, digits []byte)

@@ -16,12 +20,6 @@

// Get returns stored digits for the captcha id. Clear indicates // whether the captcha must be deleted from the store. Get(id string, clear bool) (digits []byte) - - // Collect deletes expired captchas from the store. For custom stores - // this method is not called automatically, it is only wired to the - // package's Collect function. Custom stores must implement their own - // procedure for calling Collect, for example, in Set method. - Collect() } // expValue stores timestamp and id of captchas. It is used in the list inside

@@ -67,7 +65,7 @@ s.mu.Unlock()

return } s.mu.Unlock() - go s.Collect() + go s.collect() } func (s *memoryStore) Get(id string, clear bool) (digits []byte) {

@@ -93,7 +91,7 @@ }

return } -func (s *memoryStore) Collect() { +func (s *memoryStore) collect() { now := time.Seconds() s.mu.Lock() defer s.mu.Unlock()